	.module ff.c
	.area text(rom, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\ff.c
	.dbfunc s mem_cpy _mem_cpy fV
;              s -> R20,R21
;              d -> R10,R11
;            cnt -> R22,R23
;            src -> R18,R19
;            dst -> R16,R17
	.even
_mem_cpy:
	xcall push_xgsetF00C
	ldd R22,y+6
	ldd R23,y+7
	.dbline -1
	.dbline 161
; /*----------------------------------------------------------------------------/
; /  FatFs - FAT file system module  R0.07c                    (C)ChaN, 2009
; /-----------------------------------------------------------------------------/
; / FatFs module is an open source software to implement FAT file system to
; / small embedded systems. This is a free software and is opened for education,
; / research and commercial use under license policy of following trems.
; /
; /  Copyright (C) 2009, ChaN, all right reserved.
; /
; / * The FatFs module is a free software and there is NO WARRANTY.
; / * No restriction on use. You can use, modify and redistribute it for
; /   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
; / * Redistributions of source code must retain the above copyright notice.
; /
; /-----------------------------------------------------------------------------/
; / Feb 26,'06 R0.00  Prototype.
; /
; / Apr 29,'06 R0.01  First stable version.
; /
; / Jun 01,'06 R0.02  Added FAT12 support.
; /                   Removed unbuffered mode.
; /                   Fixed a problem on small (<32M) patition.
; / Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM).
; /
; / Sep 22,'06 R0.03  Added f_rename().
; /                   Changed option _FS_MINIMUM to _FS_MINIMIZE.
; / Dec 11,'06 R0.03a Improved cluster scan algolithm to write files fast.
; /                   Fixed f_mkdir() creates incorrect directory on FAT32.
; /
; / Feb 04,'07 R0.04  Supported multiple drive system.
; /                   Changed some interfaces for multiple drive system.
; /                   Changed f_mountdrv() to f_mount().
; /                   Added f_mkfs().
; / Apr 01,'07 R0.04a Supported multiple partitions on a plysical drive.
; /                   Added a capability of extending file size to f_lseek().
; /                   Added minimization level 3.
; /                   Fixed an endian sensitive code in f_mkfs().
; / May 05,'07 R0.04b Added a configuration option _USE_NTFLAG.
; /                   Added FSInfo support.
; /                   Fixed DBCS name can result FR_INVALID_NAME.
; /                   Fixed short seek (<= csize) collapses the file object.
; /
; / Aug 25,'07 R0.05  Changed arguments of f_read(), f_write() and f_mkfs().
; /                   Fixed f_mkfs() on FAT32 creates incorrect FSInfo.
; /                   Fixed f_mkdir() on FAT32 creates incorrect directory.
; / Feb 03,'08 R0.05a Added f_truncate() and f_utime().
; /                   Fixed off by one error at FAT sub-type determination.
; /                   Fixed btr in f_read() can be mistruncated.
; /                   Fixed cached sector is not flushed when create and close
; /                   without write.
; /
; / Apr 01,'08 R0.06  Added fputc(), fputs(), fprintf() and fgets().
; /                   Improved performance of f_lseek() on moving to the same
; /                   or following cluster.
; /
; / Apr 01,'09 R0.07  Merged Tiny-FatFs as a buffer configuration option.
; /                   Added long file name support.
; /                   Added multiple code page support.
; /                   Added re-entrancy for multitask operation.
; /                   Added auto cluster size selection to f_mkfs().
; /                   Added rewind option to f_readdir().
; /                   Changed result code of critical errors.
; /                   Renamed string functions to avoid name collision.
; / Apr 14,'09 R0.07a Separated out OS dependent code on reentrant cfg.
; /                   Added multiple sector size support.
; / Jun 21,'09 R0.07c Fixed f_unlink() may return FR_OK on error.
; /                   Fixed wrong cache control in f_lseek().
; /                   Added relative path feature.
; /                   Added f_chdir() and f_chdrive().
; /                   Added proper case conversion to extended char.
; /---------------------------------------------------------------------------*/
; #include "hw_config.h"			/* FatFs configurations and declarations */
; #include "ff.h"			/* FatFs configurations and declarations */
; #include "diskio.h"		/* Declarations of low level disk I/O functions */
; /*--------------------------------------------------------------------------
; 
;    Module Private Definitions
; 
; ---------------------------------------------------------------------------*/
; 
; #if _FS_REENTRANT
; #if _USE_LFN == 1
; #error Static LFN work area must not be used in re-entrant configuration.
; #endif
; #define	ENTER_FF(fs)		{ if (!lock_fs(fs)) return FR_TIMEOUT; }
; #define	LEAVE_FF(fs, res)	{ unlock_fs(fs, res); return res; }
; 
; #else
; #define	ENTER_FF(fs)
; #define LEAVE_FF(fs, res)	return res
; 
; #endif
; 
; #define	ABORT(fs, res)		{ fp->flag |= FA__ERROR; LEAVE_FF(fs, res); }
; 
; #ifndef NULL
; #define	NULL	0
; #endif
; 
; /* Name status flags */
; #define NS_LOSS		0x01	/* Lossy conversion */
; #define NS_LFN		0x02	/* Force to create LFN entry */
; #define NS_LAST		0x04	/* Last segment */
; #define NS_BODY		0x08	/* Lower case flag (body) */
; #define NS_EXT		0x10	/* Lower case flag (ext) */
; #define NS_DOT		0x20	/* Dot entry */
; 
; 
; 
; 
; /*--------------------------------------------------------------------------
; 
;    Private Work Area
; 
; ---------------------------------------------------------------------------*/
; 
; static
; FATFS *FatFs[_DRIVES];	/* Pointer to the file system objects (logical drives) */
; 
; static
; WORD Fsid;				/* File system mount ID */
; 
; #if _FS_RPATH
; static
; BYTE Drive;				/* Current drive */
; #endif
; 
; 
; #if _USE_LFN == 1	/* LFN with static LFN working buffer */
; static
; WORD LfnBuf[_MAX_LFN + 1];
; #define	NAMEBUF(sp,lp)	BYTE sp[12]; WCHAR *lp = LfnBuf
; #define INITBUF(dj,sp,lp)	dj.fn = sp; dj.lfn = lp
; 
; #elif _USE_LFN > 1	/* LFN with dynamic LFN working buffer */
; #define	NAMEBUF(sp,lp)	BYTE sp[12]; WCHAR lbuf[_MAX_LFN + 1], *lp = lbuf
; #define INITBUF(dj,sp,lp)	dj.fn = sp; dj.lfn = lp
; 
; #else				/* No LFN */
; #define	NAMEBUF(sp,lp)	BYTE sp[12]
; #define INITBUF(dj,sp,lp)	dj.fn = sp
; 
; #endif
; 
; 
; 
; 
; /*--------------------------------------------------------------------------
; 
;    Private Functions
; 
; ---------------------------------------------------------------------------*/
; 
; 
; /*-----------------------------------------------------------------------*/
; /* String functions                                                      */
; /*-----------------------------------------------------------------------*/
; 
; /* Copy memory to memory */
; static
; void mem_cpy (void* dst, const void* src, int cnt) {
	.dbline 162
; 	char *d = (char*)dst;
	movw R10,R16
	.dbline 163
; 	const char *s = (const char *)src;
	movw R20,R18
	xjmp L7
L6:
	.dbline 164
; 	while (cnt--) *d++ = *s++;
	movw R2,R20
	subi R20,255  ; offset = 1
	sbci R21,255
	movw R30,R2
	lpm R2,Z
	movw R30,R10
	st Z+,R2
	movw R10,R30
L7:
	.dbline 164
	movw R2,R22
	subi R22,1
	sbci R23,0
	tst R2
	brne L6
	tst R3
	brne L6
X0:
	.dbline -2
L5:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r s 20 pkc
	.dbsym r d 10 pc
	.dbsym r cnt 22 I
	.dbsym r src 18 pkV
	.dbsym r dst 16 pV
	.dbend
	.dbfunc s mem_set _mem_set fV
;              d -> R10,R11
;            cnt -> R20,R21
;            val -> R18,R19
;            dst -> R16,R17
	.even
_mem_set:
	xcall push_xgset300C
	ldd R20,y+4
	ldd R21,y+5
	.dbline -1
	.dbline 169
; }
; 
; /* Fill memory */
; static
; void mem_set (void* dst, int val, int cnt) {
	.dbline 170
; 	char *d = (char*)dst;
	movw R10,R16
	xjmp L11
L10:
	.dbline 171
; 	while (cnt--) *d++ = (char)val;
	movw R30,R10
	st Z+,R18
	movw R10,R30
L11:
	.dbline 171
	movw R2,R20
	subi R20,1
	sbci R21,0
	tst R2
	brne L10
	tst R3
	brne L10
X1:
	.dbline -2
L9:
	.dbline 0 ; func end
	xjmp pop_xgset300C
	.dbsym r d 10 pc
	.dbsym r cnt 20 I
	.dbsym r val 18 I
	.dbsym r dst 16 pV
	.dbend
	.dbfunc s mem_cmp _mem_cmp fI
;              s -> R22,R23
;              d -> R20,R21
;              r -> R10,R11
;            cnt -> R14,R15
;            src -> R18,R19
;            dst -> R16,R17
	.even
_mem_cmp:
	xcall push_xgsetF0FC
	ldd R14,y+10
	ldd R15,y+11
	.dbline -1
	.dbline 176
; }
; 
; /* Compare memory to memory */
; static
; int mem_cmp (const void* dst, const void* src, int cnt) {
	.dbline 177
; 	const char *d = (const char *)dst, *s = (const char *)src;
	movw R20,R16
	.dbline 177
	movw R22,R18
	.dbline 178
; 	int r = 0;
	clr R10
	clr R11
L14:
	.dbline 179
; 	while (cnt-- && (r = *d++ - *s++) == 0) ;
L15:
	.dbline 179
	movw R2,R14
	movw R24,R2
	sbiw R24,1
	movw R14,R24
	tst R2
	brne X2
	tst R3
	breq L17
X2:
	movw R4,R20
	subi R20,255  ; offset = 1
	sbci R21,255
	movw R12,R22
	subi R22,255  ; offset = 1
	sbci R23,255
	movw R30,R12
	lpm R2,Z
	clr R3
	movw R30,R4
	lpm R12,Z
	clr R13
	sub R12,R2
	sbc R13,R3
	movw R10,R12
	tst R10
	brne X3
	tst R11
	breq L14
X3:
L17:
	.dbline 180
; 	return r;
	movw R16,R10
	.dbline -2
L13:
	.dbline 0 ; func end
	xjmp pop_xgsetF0FC
	.dbsym r s 22 pkc
	.dbsym r d 20 pkc
	.dbsym r r 10 I
	.dbsym r cnt 14 I
	.dbsym r src 18 pkV
	.dbsym r dst 16 pkV
	.dbend
	.dbfunc s chk_chr _chk_chr fI
;            chr -> R18,R19
;            str -> R16,R17
	.even
_chk_chr:
	.dbline -1
	.dbline 185
; }
; 
; /* Check if chr is contained in the string */
; static
; int chk_chr (const char* str, int chr) {
	xjmp L20
L19:
	.dbline 186
; 	while (*str && *str != chr) str++;
	subi R16,255  ; offset = 1
	sbci R17,255
L20:
	.dbline 186
	movw R30,R16
	lpm R2,Z
	clr R3
	tst R2
	breq L22
X4:
	clr R3
	cp R2,R18
	cpc R3,R19
	brne L19
X5:
L22:
	.dbline 187
; 	return *str;
	movw R30,R16
	lpm R16,Z
	clr R17
	.dbline -2
L18:
	.dbline 0 ; func end
	ret
	.dbsym r chr 18 I
	.dbsym r str 16 pkc
	.dbend
	.dbfunc s move_window _move_window fc
	.dbstruct 0 558 _FATFS_
	.dbfield 0 fs_type c
	.dbfield 1 drive c
	.dbfield 2 csize c
	.dbfield 3 n_fats c
	.dbfield 4 wflag c
	.dbfield 5 id s
	.dbfield 7 n_rootdir s
	.dbfield 9 fsi_flag c
	.dbfield 10 last_clust l
	.dbfield 14 free_clust l
	.dbfield 18 fsi_sector l
	.dbfield 22 sects_fat l
	.dbfield 26 max_clust l
	.dbfield 30 fatbase l
	.dbfield 34 dirbase l
	.dbfield 38 database l
	.dbfield 42 winsect l
	.dbfield 46 win A[512:512]c
	.dbend
;             nf -> R12
;          wsect -> y+5
;         sector -> y+17
;             fs -> R10,R11
	.even
_move_window:
	st -y,r19
	st -y,r18
	xcall push_xgsetF03C
	movw R10,R16
	sbiw R28,9
	.dbline -1
	.dbline 232
; }
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Request/Release grant to access the volume                            */
; /*-----------------------------------------------------------------------*/
; #if _FS_REENTRANT
; 
; static
; BOOL lock_fs (
; 	FATFS *fs		/* File system object */
; )
; {
; 	return ff_req_grant(fs->sobj);
; }
; 
; 
; static
; void unlock_fs (
; 	FATFS *fs,		/* File system object */
; 	FRESULT res		/* Result code to be returned */
; )
; {
; 	if (res != FR_NOT_ENABLED &&
; 		res != FR_INVALID_DRIVE &&
; 		res != FR_INVALID_OBJECT &&
; 		res != FR_TIMEOUT) {
; 		ff_rel_grant(fs->sobj);
; 	}
; }
; #endif
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Change window offset                                                  */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT move_window (
; 	FATFS *fs,		/* File system object */
; 	DWORD sector	/* Sector number to make apperance in the fs->win[] */
; )					/* Move to zero only writes back dirty window */
; {
	.dbline 236
; 	DWORD wsect;
; 
; 
; 	wsect = fs->winsect;
	movw R30,R10
	ldd R2,z+42
	ldd R3,z+43
	ldd R4,z+44
	ldd R5,z+45
	std y+5,R2
	std y+6,R3
	std y+7,R4
	std y+8,R5
	.dbline 237
; 	if (wsect != sector) {	/* Changed current window */
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	ldd R6,y+5
	ldd R7,y+6
	ldd R8,y+7
	ldd R9,y+8
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne X13
	xjmp L24
X13:
X6:
	.dbline 237
	.dbline 239
; #if !_FS_READONLY
; 		if (fs->wflag) {	/* Write back dirty window if needed */
	ldd R2,z+4
	tst R2
	brne X14
	xjmp L26
X14:
X7:
	.dbline 239
	.dbline 240
; 			if (disk_write(fs->drive, fs->win, wsect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	movw R2,R6
	movw R4,R8
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,210  ; offset = 46
	sbci R19,255
	ldd R16,z+1
	xcall _disk_write
	tst R16
	breq L28
X8:
	.dbline 241
; 				return FR_DISK_ERR;
	ldi R16,1
	xjmp L23
L28:
	.dbline 242
; 			fs->wflag = 0;
	clr R2
	movw R30,R10
	std z+4,R2
	.dbline 243
; 			if (wsect < (fs->fatbase + fs->sects_fat)) {	/* In FAT area */
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	ldd R6,z+30
	ldd R7,z+31
	ldd R8,z+32
	ldd R9,z+33
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brsh L30
X9:
	.dbline 243
	.dbline 245
; 				BYTE nf;
; 				for (nf = fs->n_fats; nf > 1; nf--) {	/* Refrect the change to all FAT copies */
	ldd R12,z+3
	xjmp L35
L32:
	.dbline 245
	.dbline 246
; 					wsect += fs->sects_fat;
	movw R30,R10
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	ldd R6,y+5
	ldd R7,y+6
	ldd R8,y+7
	ldd R9,y+8
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+5,R6
	std y+6,R7
	std y+7,R8
	std y+8,R9
	.dbline 247
; 					disk_write(fs->drive, fs->win, wsect, 1);
	ldi R24,1
	std y+4,R24
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,210  ; offset = 46
	sbci R19,255
	ldd R16,z+1
	xcall _disk_write
	.dbline 248
; 				}
L33:
	.dbline 245
	dec R12
L35:
	.dbline 245
	ldi R24,1
	cp R24,R12
	brlo L32
X10:
	.dbline 249
; 			}
L30:
	.dbline 250
; 		}
L26:
	.dbline 252
; #endif
; 		if (sector) {
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L36
X11:
	.dbline 252
	.dbline 253
; 			if (disk_read(fs->drive, fs->win, sector, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R10
	subi R18,210  ; offset = 46
	sbci R19,255
	movw R30,R10
	ldd R16,z+1
	xcall _disk_read
	tst R16
	breq L38
X12:
	.dbline 254
; 				return FR_DISK_ERR;
	ldi R16,1
	xjmp L23
L38:
	.dbline 255
; 			fs->winsect = sector;
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	movw R30,R10
	std z+42,R2
	std z+43,R3
	std z+44,R4
	std z+45,R5
	.dbline 256
; 		}
L36:
	.dbline 257
; 	}
L24:
	.dbline 259
; 
; 	return FR_OK;
	clr R16
	.dbline -2
L23:
	.dbline 0 ; func end
	adiw R28,9
	xcall pop_xgsetF03C
	adiw R28,2
	ret
	.dbsym r nf 12 c
	.dbsym l wsect 5 l
	.dbsym l sector 17 l
	.dbsym r fs 10 pS[_FATFS_]
	.dbend
	.dbfunc s sync _sync fc
;            res -> R20
;             fs -> R22,R23
	.even
_sync:
	xcall push_xgsetF000
	movw R22,R16
	sbiw R28,5
	.dbline -1
	.dbline 273
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Clean-up cached data                                                  */
; /*-----------------------------------------------------------------------*/
; #if !_FS_READONLY
; static
; FRESULT sync (	/* FR_OK: successful, FR_DISK_ERR: failed */
; 	FATFS *fs	/* File system object */
; )
; {
	.dbline 277
; 	FRESULT res;
; 
; 
; 	res = move_window(fs, 0);
	ldi R24,0
	ldi R25,0
	ldi R26,0
	ldi R27,0
	std y+0,R26
	std y+1,R27
	movw R18,R24
	movw R16,R22
	xcall _move_window
	mov R20,R16
	.dbline 278
; 	if (res == FR_OK) {
	tst R16
	breq X19
	xjmp L41
X19:
X15:
	.dbline 278
	.dbline 280
; 		/* Update FSInfo sector if needed */
; 		if (fs->fs_type == FS_FAT32 && fs->fsi_flag) {
	movw R30,R22
	ldd R24,z+0
	cpi R24,3
	breq X20
	xjmp L43
X20:
X16:
	ldd R2,z+9
	tst R2
	brne X21
	xjmp L43
X21:
X17:
	.dbline 280
	.dbline 281
; 			fs->winsect = 0;
	ldi R24,0
	ldi R25,0
	ldi R26,0
	ldi R27,0
	std z+42,R24
	std z+43,R25
	std z+44,R26
	std z+45,R27
	.dbline 282
; 			mem_set(fs->win, 0, 512);
	ldi R24,512
	ldi R25,2
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	movw R16,R30
	subi R16,210  ; offset = 46
	sbci R17,255
	xcall _mem_set
	.dbline 283
; 			ST_WORD(fs->win+BS_55AA, 0xAA55);
	ldi R24,43605
	ldi R25,170
	movw R30,R22
	subi R30,212  ; addi 556
	sbci R31,253
	std z+0,R24
	subi R30,44
	sbci R31,2
	.dbline 283
	ldi R24,170
	subi R30,211  ; addi 557
	sbci R31,253
	std z+0,R24
	subi R30,45
	sbci R31,2
	.dbline 284
; 			ST_DWORD(fs->win+FSI_LeadSig, 0x41615252);
	ldi R24,82
	ldi R25,82
	ldi R26,97
	ldi R27,65
	movw R2,R24
	std z+46,R2
	.dbline 284
	ldi R24,82
	ldi R25,82
	ldi R26,97
	ldi R27,65
	movw R2,R24
	mov R2,R3
	clr R3
	std z+47,R2
	.dbline 284
	ldi R24,97
	ldi R25,65
	ldi R26,0
	ldi R27,0
	std z+48,R24
	.dbline 284
	ldi R24,65
	std z+49,R24
	.dbline 285
; 			ST_DWORD(fs->win+FSI_StrucSig, 0x61417272);
	ldi R24,114
	ldi R25,114
	ldi R26,65
	ldi R27,97
	movw R2,R24
	subi R30,238  ; addi 530
	sbci R31,253
	std z+0,R2
	subi R30,18
	sbci R31,2
	.dbline 285
	ldi R24,114
	ldi R25,114
	ldi R26,65
	ldi R27,97
	movw R2,R24
	mov R2,R3
	clr R3
	subi R30,237  ; addi 531
	sbci R31,253
	std z+0,R2
	subi R30,19
	sbci R31,2
	.dbline 285
	ldi R24,65
	ldi R25,97
	ldi R26,0
	ldi R27,0
	subi R30,236  ; addi 532
	sbci R31,253
	std z+0,R24
	subi R30,20
	sbci R31,2
	.dbline 285
	ldi R24,97
	subi R30,235  ; addi 533
	sbci R31,253
	std z+0,R24
	subi R30,21
	sbci R31,2
	.dbline 286
; 			ST_DWORD(fs->win+FSI_Free_Count, fs->free_clust);
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	subi R30,234  ; addi 534
	sbci R31,253
	std z+0,R2
	subi R30,22
	sbci R31,2
	.dbline 286
	ldd R2,z+14
	ldd R3,z+15
	mov R2,R3
	clr R3
	subi R30,233  ; addi 535
	sbci R31,253
	std z+0,R2
	subi R30,23
	sbci R31,2
	.dbline 286
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	movw R2,R4
	clr R4
	clr R5
	subi R30,232  ; addi 536
	sbci R31,253
	std z+0,R2
	subi R30,24
	sbci R31,2
	.dbline 286
	ldi R24,24
	ldi R25,0
	ldd R16,z+14
	ldd R17,z+15
	ldd R18,z+16
	ldd R19,z+17
	st -y,R24
	xcall lsr32
	movw R30,R22
	subi R30,231  ; addi 537
	sbci R31,253
	std z+0,R16
	subi R30,25
	sbci R31,2
	.dbline 287
; 			ST_DWORD(fs->win+FSI_Nxt_Free, fs->last_clust);
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	subi R30,230  ; addi 538
	sbci R31,253
	std z+0,R2
	subi R30,26
	sbci R31,2
	.dbline 287
	ldd R2,z+10
	ldd R3,z+11
	mov R2,R3
	clr R3
	subi R30,229  ; addi 539
	sbci R31,253
	std z+0,R2
	subi R30,27
	sbci R31,2
	.dbline 287
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	movw R2,R4
	clr R4
	clr R5
	subi R30,228  ; addi 540
	sbci R31,253
	std z+0,R2
	subi R30,28
	sbci R31,2
	.dbline 287
	ldi R24,24
	ldi R25,0
	ldd R16,z+10
	ldd R17,z+11
	ldd R18,z+12
	ldd R19,z+13
	st -y,R24
	xcall lsr32
	movw R30,R22
	subi R30,227  ; addi 541
	sbci R31,253
	std z+0,R16
	subi R30,29
	sbci R31,2
	.dbline 288
; 			disk_write(fs->drive, fs->win, fs->fsi_sector, 1);
	ldi R24,1
	std y+4,R24
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,210  ; offset = 46
	sbci R19,255
	ldd R16,z+1
	xcall _disk_write
	.dbline 289
; 			fs->fsi_flag = 0;
	clr R2
	movw R30,R22
	std z+9,R2
	.dbline 290
; 		}
L43:
	.dbline 292
; 		/* Make sure that no pending write process in the physical drive */
; 		if (disk_ioctl(fs->drive, CTRL_SYNC, (void*)NULL) != RES_OK)
	clr R2
	clr R3
	std y+1,R3
	std y+0,R2
	clr R18
	movw R30,R22
	ldd R16,z+1
	xcall _disk_ioctl
	tst R16
	breq L45
X18:
	.dbline 293
; 			res = FR_DISK_ERR;
	ldi R20,1
L45:
	.dbline 294
; 	}
L41:
	.dbline 296
; 
; 	return res;
	mov R16,R20
	.dbline -2
L40:
	.dbline 0 ; func end
	adiw R28,5
	xjmp pop_xgsetF000
	.dbsym r res 20 c
	.dbsym r fs 22 pS[_FATFS_]
	.dbend
	.dbfunc s get_fat _get_fat fl
;             wc -> R14,R15
;             bc -> R12,R13
;          fsect -> y+2
;           clst -> y+16
;             fs -> R10,R11
	.even
_get_fat:
	st -y,r19
	st -y,r18
	xcall push_xgsetF0FC
	movw R10,R16
	sbiw R28,6
	.dbline -1
	.dbline 312
; }
; #endif
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* FAT access - Read value of a FAT entry                                */
; /*-----------------------------------------------------------------------*/
; 
; static
; DWORD get_fat (	/* 0xFFFFFFFF:Disk error, 1:Interal error, Else:Cluster status */
; 	FATFS *fs,	/* File system object */
; 	DWORD clst	/* Cluster# to get the link information */
; )
; {
	.dbline 317
; 	UINT wc, bc;
; 	DWORD fsect;
; 
; 
; 	if (clst < 2 || clst >= fs->max_clust)	/* Range check */
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+16
	ldd R3,y+17
	ldd R4,y+18
	ldd R5,y+19
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L50
X22:
	movw R30,R10
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	ldd R6,y+16
	ldd R7,y+17
	ldd R8,y+18
	ldd R9,y+19
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L48
X23:
L50:
	.dbline 318
; 		return 1;
	ldi R16,1
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L47
L48:
	.dbline 320
; 
; 	fsect = fs->fatbase;
	movw R30,R10
	ldd R2,z+30
	ldd R3,z+31
	ldd R4,z+32
	ldd R5,z+33
	std y+2,R2
	std y+3,R3
	std y+4,R4
	std y+5,R5
	.dbline 321
; 	switch (fs->fs_type) {
	ldd R12,z+0
	clr R13
	movw R24,R12
	cpi R24,1
	ldi R30,0
	cpc R25,R30
	breq L54
X24:
	cpi R24,2
	ldi R30,0
	cpc R25,R30
	brne X32
	xjmp L61
X32:
X25:
	cpi R24,3
	ldi R30,0
	cpc R25,R30
	brne X33
	xjmp L64
X33:
X26:
	xjmp L51
L54:
	.dbline 323
; 	case FS_FAT12 :
; 		bc = clst; bc += bc / 2;
	ldd R12,y+16
	ldd R13,y+17
	.dbline 323
	movw R2,R12
	lsr R3
	ror R2
	add R12,R2
	adc R13,R3
	.dbline 324
; 		if (move_window(fs, fsect + (bc / SS(fs)))) break;
	ldi R18,9
	ldi R19,0
	movw R16,R12
	xcall lsr16
	movw R2,R16
	clr R4
	clr R5
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+0,R8
	std y+1,R9
	movw R18,R6
	movw R16,R10
	xcall _move_window
	tst R16
	breq L55
X27:
	.dbline 324
	xjmp L52
L55:
	.dbline 325
; 		wc = fs->win[bc & (SS(fs) - 1)]; bc++;
	movw R24,R10
	adiw R24,46
	movw R30,R12
	andi R31,1
	add R30,R24
	adc R31,R25
	ldd R14,z+0
	clr R15
	.dbline 325
	movw R24,R12
	adiw R24,1
	movw R12,R24
	.dbline 326
; 		if (move_window(fs, fsect + (bc / SS(fs)))) break;
	ldi R18,9
	ldi R19,0
	movw R16,R24
	xcall lsr16
	movw R2,R16
	clr R4
	clr R5
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+0,R8
	std y+1,R9
	movw R18,R6
	movw R16,R10
	xcall _move_window
	tst R16
	breq L57
X28:
	.dbline 326
	xjmp L52
L57:
	.dbline 327
; 		wc |= (WORD)fs->win[bc & (SS(fs) - 1)] << 8;
	movw R24,R10
	adiw R24,46
	movw R30,R12
	andi R31,1
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	clr R3
	mov R3,R2
	clr R2
	or R14,R2
	or R15,R3
	.dbline 328
; 		return (clst & 1) ? (wc >> 4) : (wc & 0xFFF);
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+16
	ldd R3,y+17
	ldd R4,y+18
	ldd R5,y+19
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L59
X29:
	movw R12,R14
	lsr R13
	ror R12
	lsr R13
	ror R12
	lsr R13
	ror R12
	lsr R13
	ror R12
	xjmp L60
L59:
	movw R24,R14
	andi R25,15
	movw R12,R24
L60:
	movw R16,R12
	movw R18,R14
	clr R18
	clr R19
	xjmp L47
L61:
	.dbline 331
; 
; 	case FS_FAT16 :
; 		if (move_window(fs, fsect + (clst / (SS(fs) / 2)))) break;
	ldi R24,8
	ldi R25,0
	ldd R16,y+16
	ldd R17,y+17
	ldd R18,y+18
	ldd R19,y+19
	st -y,R24
	xcall lsr32
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	add R2,R16
	adc R3,R17
	adc R4,R18
	adc R5,R19
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R10
	xcall _move_window
	mov R12,R16
	tst R16
	breq L62
X30:
	.dbline 331
	xjmp L52
L62:
	.dbline 332
; 		return LD_WORD(&fs->win[((WORD)clst * 2) & (SS(fs) - 1)]);
	ldd R18,y+16
	ldd R19,y+17
	ldi R16,2
	ldi R17,0
	xcall empy16s
	movw R24,R16
	andi R25,1
	movw R30,R10
	adiw R30,46
	movw R12,R24
	add R12,R30
	adc R13,R31
	movw R30,R12
	ldd R2,z+0
	clr R3
	ldd R16,z+1
	clr R17
	mov R17,R16
	clr R16
	or R16,R2
	or R17,R3
	clr R18
	clr R19
	xjmp L47
L64:
	.dbline 335
; 
; 	case FS_FAT32 :
; 		if (move_window(fs, fsect + (clst / (SS(fs) / 4)))) break;
	ldi R24,7
	ldi R25,0
	ldd R16,y+16
	ldd R17,y+17
	ldd R18,y+18
	ldd R19,y+19
	st -y,R24
	xcall lsr32
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	add R2,R16
	adc R3,R17
	adc R4,R18
	adc R5,R19
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R10
	xcall _move_window
	mov R12,R16
	tst R16
	breq L65
X31:
	.dbline 335
	xjmp L52
L65:
	.dbline 336
; 		return LD_DWORD(&fs->win[((WORD)clst * 4) & (SS(fs) - 1)]) & 0x0FFFFFFF;
	ldd R18,y+16
	ldd R19,y+17
	ldi R16,4
	ldi R17,0
	xcall empy16s
	movw R24,R16
	andi R25,1
	movw R30,R10
	adiw R30,46
	movw R10,R24
	add R10,R30
	adc R11,R31
	ldi R24,24
	ldi R25,0
	movw R30,R10
	ldd R16,z+3
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R10
	ldd R6,z+2
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+1
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+0
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,15
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	movw R16,R2
	movw R18,R4
	xjmp L47
L51:
L52:
	.dbline 339
; 	}
; 
; 	return 0xFFFFFFFF;	/* An error occured at the disk I/O layer */
	ldi R16,255
	ldi R17,255
	ldi R18,255
	ldi R19,255
	.dbline -2
L47:
	.dbline 0 ; func end
	adiw R28,6
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym r wc 14 i
	.dbsym r bc 12 i
	.dbsym l fsect 2 l
	.dbsym l clst 16 l
	.dbsym r fs 10 pS[_FATFS_]
	.dbend
	.dbfunc s put_fat _put_fat fc
;              p -> R14,R15
;             bc -> R12,R13
;          fsect -> y+2
;            res -> y+6
;            val -> y+23
;           clst -> y+19
;             fs -> y+17
	.even
_put_fat:
	xcall push_arg4
	xcall push_xgsetF0FC
	sbiw R28,7
	.dbline -1
	.dbline 355
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* FAT access - Change value of a FAT entry                              */
; /*-----------------------------------------------------------------------*/
; #if !_FS_READONLY
; static
; FRESULT put_fat (
; 	FATFS *fs,	/* File system object */
; 	DWORD clst,	/* Cluster# to be changed in range of 2 to fs->max_clust - 1 */
; 	DWORD val	/* New value to mark the cluster */
; )
; {
	.dbline 362
; 	UINT bc;
; 	BYTE *p;
; 	DWORD fsect;
; 	FRESULT res;
; 
; 
; 	if (clst < 2 || clst >= fs->max_clust) {	/* Range check */
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+19
	ldd R3,y+20
	ldd R4,y+21
	ldd R5,y+22
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L70
X34:
	ldd R30,y+17
	ldd R31,y+18
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	ldd R6,y+19
	ldd R7,y+20
	ldd R8,y+21
	ldd R9,y+22
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L68
X35:
L70:
	.dbline 362
	.dbline 363
; 		res = FR_INT_ERR;
	ldi R24,2
	std y+6,R24
	.dbline 365
; 
; 	} else {
	xjmp L69
L68:
	.dbline 365
	.dbline 366
; 		fsect = fs->fatbase;
	ldd R30,y+17
	ldd R31,y+18
	ldd R2,z+30
	ldd R3,z+31
	ldd R4,z+32
	ldd R5,z+33
	std y+2,R2
	std y+3,R3
	std y+4,R4
	std y+5,R5
	.dbline 367
; 		switch (fs->fs_type) {
	ldd R30,y+17
	ldd R31,y+18
	ldd R10,z+0
	clr R11
	movw R24,R10
	cpi R24,1
	ldi R30,0
	cpc R25,R30
	breq L74
X36:
	cpi R24,2
	ldi R30,0
	cpc R25,R30
	brne X45
	xjmp L83
X45:
X37:
	cpi R24,3
	ldi R30,0
	cpc R25,R30
	brne X46
	xjmp L86
X46:
X38:
	xjmp L71
L74:
	.dbline 369
; 		case FS_FAT12 :
; 			bc = clst; bc += bc / 2;
	ldd R12,y+19
	ldd R13,y+20
	.dbline 369
	movw R2,R12
	lsr R3
	ror R2
	add R12,R2
	adc R13,R3
	.dbline 370
; 			res = move_window(fs, fsect + (bc / SS(fs)));
	ldi R18,9
	ldi R19,0
	movw R16,R12
	xcall lsr16
	movw R2,R16
	clr R4
	clr R5
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+0,R8
	std y+1,R9
	movw R18,R6
	ldd R16,y+17
	ldd R17,y+18
	xcall _move_window
	std y+6,R16
	.dbline 371
; 			if (res != FR_OK) break;
	mov R0,R16
	tst R16
	breq L75
X39:
	.dbline 371
	xjmp L72
L75:
	.dbline 372
; 			p = &fs->win[bc & (SS(fs) - 1)];
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	movw R30,R12
	andi R31,1
	movw R14,R30
	add R14,R24
	adc R15,R25
	.dbline 373
; 			*p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+19
	ldd R3,y+20
	ldd R4,y+21
	ldd R5,y+22
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L77
X40:
	ldd R2,y+23
	ldd R3,y+24
	ldd R4,y+25
	ldd R5,y+26
	clr R3
	lsl R2
	rol R3
	lsl R2
	rol R3
	lsl R2
	rol R3
	lsl R2
	rol R3
	movw R30,R14
	ldd R24,z+0
	clr R25
	andi R24,15
	andi R25,0
	movw R10,R24
	or R10,R2
	or R11,R3
	xjmp L78
L77:
	ldd R2,y+23
	ldd R3,y+24
	ldd R4,y+25
	ldd R5,y+26
	mov R10,R2
	clr R11
L78:
	movw R30,R14
	std z+0,R10
	.dbline 374
; 			bc++;
	movw R24,R12
	adiw R24,1
	movw R12,R24
	.dbline 375
; 			fs->wflag = 1;
	ldi R24,1
	ldd R30,y+17
	ldd R31,y+18
	std z+4,R24
	.dbline 376
; 			res = move_window(fs, fsect + (bc / SS(fs)));
	ldi R18,9
	ldi R19,0
	movw R16,R12
	xcall lsr16
	movw R2,R16
	clr R4
	clr R5
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+0,R8
	std y+1,R9
	movw R18,R6
	ldd R16,y+17
	ldd R17,y+18
	xcall _move_window
	std y+6,R16
	.dbline 377
; 			if (res != FR_OK) break;
	mov R0,R16
	tst R16
	breq L79
X41:
	.dbline 377
	xjmp L72
L79:
	.dbline 378
; 			p = &fs->win[bc & (SS(fs) - 1)];
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	movw R30,R12
	andi R31,1
	movw R14,R30
	add R14,R24
	adc R15,R25
	.dbline 379
; 			*p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+19
	ldd R3,y+20
	ldd R4,y+21
	ldd R5,y+22
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L81
X42:
	ldi R24,4
	ldi R25,0
	ldd R16,y+23
	ldd R17,y+24
	ldd R18,y+25
	ldd R19,y+26
	st -y,R24
	xcall lsr32
	mov R12,R16
	clr R13
	xjmp L82
L81:
	ldi R24,8
	ldi R25,0
	ldd R16,y+23
	ldd R17,y+24
	ldd R18,y+25
	ldd R19,y+26
	st -y,R24
	xcall lsr32
	mov R24,R16
	clr R25
	andi R24,15
	andi R25,0
	movw R30,R14
	ldd R30,z+0
	clr R31
	andi R30,240
	andi R31,0
	movw R12,R30
	or R12,R24
	or R13,R25
L82:
	movw R30,R14
	std z+0,R12
	.dbline 380
; 			break;
	xjmp L72
L83:
	.dbline 383
; 
; 		case FS_FAT16 :
; 			res = move_window(fs, fsect + (clst / (SS(fs) / 2)));
	ldi R24,8
	ldi R25,0
	ldd R16,y+19
	ldd R17,y+20
	ldd R18,y+21
	ldd R19,y+22
	st -y,R24
	xcall lsr32
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	add R2,R16
	adc R3,R17
	adc R4,R18
	adc R5,R19
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+17
	ldd R17,y+18
	xcall _move_window
	mov R14,R16
	std y+6,R14
	.dbline 384
; 			if (res != FR_OK) break;
	mov R0,R14
	tst R16
	breq L84
X43:
	.dbline 384
	xjmp L72
L84:
	.dbline 385
; 			ST_WORD(&fs->win[((WORD)clst * 2) & (SS(fs) - 1)], (WORD)val);
	ldd R18,y+19
	ldd R19,y+20
	ldi R16,2
	ldi R17,0
	xcall empy16s
	movw R30,R16
	andi R31,1
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	add R30,R24
	adc R31,R25
	ldd R2,y+23
	ldd R3,y+24
	std z+0,R2
	.dbline 385
	ldd R18,y+19
	ldd R19,y+20
	ldi R16,2
	ldi R17,0
	xcall empy16s
	movw R30,R16
	andi R31,1
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	add R30,R24
	adc R31,R25
	ldd R2,y+23
	ldd R3,y+24
	mov R2,R3
	clr R3
	std z+1,R2
	.dbline 386
; 			break;
	xjmp L72
L86:
	.dbline 389
; 
; 		case FS_FAT32 :
; 			res = move_window(fs, fsect + (clst / (SS(fs) / 4)));
	ldi R24,7
	ldi R25,0
	ldd R16,y+19
	ldd R17,y+20
	ldd R18,y+21
	ldd R19,y+22
	st -y,R24
	xcall lsr32
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	add R2,R16
	adc R3,R17
	adc R4,R18
	adc R5,R19
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+17
	ldd R17,y+18
	xcall _move_window
	mov R14,R16
	std y+6,R14
	.dbline 390
; 			if (res != FR_OK) break;
	mov R0,R14
	tst R16
	breq L87
X44:
	.dbline 390
	xjmp L72
L87:
	.dbline 391
; 			ST_DWORD(&fs->win[((WORD)clst * 4) & (SS(fs) - 1)], val);
	ldd R18,y+19
	ldd R19,y+20
	ldi R16,4
	ldi R17,0
	xcall empy16s
	movw R30,R16
	andi R31,1
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	add R30,R24
	adc R31,R25
	ldd R2,y+23
	ldd R3,y+24
	ldd R4,y+25
	ldd R5,y+26
	std z+0,R2
	.dbline 391
	ldd R18,y+19
	ldd R19,y+20
	ldi R16,4
	ldi R17,0
	xcall empy16s
	movw R30,R16
	andi R31,1
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	add R30,R24
	adc R31,R25
	ldd R2,y+23
	ldd R3,y+24
	mov R2,R3
	clr R3
	std z+1,R2
	.dbline 391
	ldd R18,y+19
	ldd R19,y+20
	ldi R16,4
	ldi R17,0
	xcall empy16s
	movw R30,R16
	andi R31,1
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	add R30,R24
	adc R31,R25
	ldd R2,y+23
	ldd R3,y+24
	ldd R4,y+25
	ldd R5,y+26
	movw R2,R4
	clr R4
	clr R5
	std z+2,R2
	.dbline 391
	ldd R18,y+19
	ldd R19,y+20
	ldi R16,4
	ldi R17,0
	xcall empy16s
	movw R30,R16
	andi R31,1
	ldd R24,y+17
	ldd R25,y+18
	adiw R24,46
	add R30,R24
	adc R31,R25
	ldi R24,24
	ldi R25,0
	ldd R16,y+23
	ldd R17,y+24
	ldd R18,y+25
	ldd R19,y+26
	st -y,R24
	xcall lsr32
	std z+3,R16
	.dbline 392
; 			break;
	xjmp L72
L71:
	.dbline 395
; 
; 		default :
; 			res = FR_INT_ERR;
	ldi R24,2
	std y+6,R24
	.dbline 396
; 		}
L72:
	.dbline 397
; 		fs->wflag = 1;
	ldi R24,1
	ldd R30,y+17
	ldd R31,y+18
	std z+4,R24
	.dbline 398
; 	}
L69:
	.dbline 400
; 
; 	return res;
	ldd R16,y+6
	.dbline -2
L67:
	.dbline 0 ; func end
	adiw R28,7
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym r p 14 pc
	.dbsym r bc 12 i
	.dbsym l fsect 2 l
	.dbsym l res 6 c
	.dbsym l val 23 l
	.dbsym l clst 19 l
	.dbsym l fs 17 pS[_FATFS_]
	.dbend
	.dbfunc s remove_chain _remove_chain fc
;            res -> R10
;            nxt -> y+6
;           clst -> y+18
;             fs -> R12,R13
	.even
_remove_chain:
	st -y,r19
	st -y,r18
	xcall push_xgsetF03C
	movw R12,R16
	sbiw R28,10
	.dbline -1
	.dbline 416
; }
; #endif /* !_FS_READONLY */
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* FAT handling - Remove a cluster chain                                 */
; /*-----------------------------------------------------------------------*/
; #if !_FS_READONLY
; static
; FRESULT remove_chain (
; 	FATFS *fs,			/* File system object */
; 	DWORD clst			/* Cluster# to remove a chain from */
; )
; {
	.dbline 421
; 	FRESULT res;
; 	DWORD nxt;
; 
; 
; 	if (clst < 2 || clst >= fs->max_clust) {	/* Check the range of cluster# */
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L92
X47:
	movw R30,R12
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	ldd R6,y+18
	ldd R7,y+19
	ldd R8,y+20
	ldd R9,y+21
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L90
X48:
L92:
	.dbline 421
	.dbline 422
; 		res = FR_INT_ERR;
	ldi R24,2
	mov R10,R24
	.dbline 424
; 
; 	} else {
	xjmp L91
L90:
	.dbline 424
	.dbline 425
; 		res = FR_OK;
	clr R10
	xjmp L94
L93:
	.dbline 426
; 		while (clst < fs->max_clust) {			/* Not a last link? */
	.dbline 427
; 			nxt = get_fat(fs, clst);			/* Get cluster status */
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R12
	xcall _get_fat
	std y+6,R16
	std y+7,R17
	std y+8,R18
	std y+9,R19
	.dbline 428
; 			if (nxt == 0) break;				/* Empty cluster? */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L96
X49:
	.dbline 428
	xjmp L95
L96:
	.dbline 429
; 			if (nxt == 1) { res = FR_INT_ERR; break; }	/* Internal error? */
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L98
X50:
	.dbline 429
	.dbline 429
	ldi R24,2
	mov R10,R24
	.dbline 429
	xjmp L95
L98:
	.dbline 430
; 			if (nxt == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }	/* Disk error? */
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L100
X51:
	.dbline 430
	.dbline 430
	clr R10
	inc R10
	.dbline 430
	xjmp L95
L100:
	.dbline 431
; 			res = put_fat(fs, clst, 0);			/* Mark the cluster "empty" */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+2,R20
	std y+3,R21
	std y+4,R22
	std y+5,R23
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R12
	xcall _put_fat
	mov R10,R16
	.dbline 432
; 			if (res != FR_OK) break;
	tst R16
	breq L102
X52:
	.dbline 432
	xjmp L95
L102:
	.dbline 433
; 			if (fs->free_clust != 0xFFFFFFFF) {	/* Update FSInfo */
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	movw R30,R12
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L104
X53:
	.dbline 433
	.dbline 434
; 				fs->free_clust++;
	movw R24,R30
	adiw R24,14
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R24
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 435
; 				fs->fsi_flag = 1;
	ldi R24,1
	movw R30,R12
	std z+9,R24
	.dbline 436
; 			}
L104:
	.dbline 437
; 			clst = nxt;	/* Next cluster */
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	std y+18,R2
	std y+19,R3
	std y+20,R4
	std y+21,R5
	.dbline 438
; 		}
L94:
	.dbline 426
	movw R30,R12
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	ldd R6,y+18
	ldd R7,y+19
	ldd R8,y+20
	ldd R9,y+21
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh X55
	xjmp L93
X55:
X54:
L95:
	.dbline 439
; 	}
L91:
	.dbline 441
; 
; 	return res;
	mov R16,R10
	.dbline -2
L89:
	.dbline 0 ; func end
	adiw R28,10
	xcall pop_xgsetF03C
	adiw R28,2
	ret
	.dbsym r res 10 c
	.dbsym l nxt 6 l
	.dbsym l clst 18 l
	.dbsym r fs 12 pS[_FATFS_]
	.dbend
	.dbfunc s create_chain _create_chain fl
;            mcl -> y+18
;            scl -> y+14
;             cs -> y+10
;            ncl -> y+6
;           clst -> y+30
;             fs -> R10,R11
	.even
_create_chain:
	st -y,r19
	st -y,r18
	xcall push_xgsetF03C
	movw R10,R16
	sbiw R28,22
	.dbline -1
	.dbline 457
; }
; #endif
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* FAT handling - Stretch or Create a cluster chain                      */
; /*-----------------------------------------------------------------------*/
; #if !_FS_READONLY
; static
; DWORD create_chain (	/* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */
; 	FATFS *fs,			/* File system object */
; 	DWORD clst			/* Cluster# to stretch. 0 means create a new chain. */
; )
; {
	.dbline 461
; 	DWORD cs, ncl, scl, mcl;
; 
; 
; 	mcl = fs->max_clust;
	movw R30,R10
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	std y+18,R2
	std y+19,R3
	std y+20,R4
	std y+21,R5
	.dbline 462
; 	if (clst == 0) {		/* Create new chain */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+30
	ldd R3,y+31
	ldd R4,y+32
	ldd R5,y+33
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L107
X56:
	.dbline 462
	.dbline 463
; 		scl = fs->last_clust;			/* Get suggested start point */
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	std y+14,R2
	std y+15,R3
	std y+16,R4
	std y+17,R5
	.dbline 464
; 		if (scl == 0 || scl >= mcl) scl = 1;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+14
	ldd R3,y+15
	ldd R4,y+16
	ldd R5,y+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L111
X57:
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	ldd R6,y+14
	ldd R7,y+15
	ldd R8,y+16
	ldd R9,y+17
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh X71
	xjmp L108
X71:
X58:
L111:
	.dbline 464
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+14,R20
	std y+15,R21
	std y+16,R22
	std y+17,R23
	.dbline 465
; 	}
	xjmp L108
L107:
	.dbline 466
; 	else {					/* Stretch existing chain */
	.dbline 467
; 		cs = get_fat(fs, clst);			/* Check the cluster status */
	ldd R2,y+30
	ldd R3,y+31
	ldd R4,y+32
	ldd R5,y+33
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R10
	xcall _get_fat
	std y+10,R16
	std y+11,R17
	std y+12,R18
	std y+13,R19
	.dbline 468
; 		if (cs < 2) return 1;			/* It is an invalid cluster */
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brsh L112
X59:
	.dbline 468
	ldi R16,1
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L106
L112:
	.dbline 469
; 		if (cs < mcl) return cs;		/* It is already followed by next cluster */
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	ldd R6,y+10
	ldd R7,y+11
	ldd R8,y+12
	ldd R9,y+13
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh L114
X60:
	.dbline 469
	movw R16,R6
	movw R18,R8
	xjmp L106
L114:
	.dbline 470
; 		scl = clst;
	ldd R2,y+30
	ldd R3,y+31
	ldd R4,y+32
	ldd R5,y+33
	std y+14,R2
	std y+15,R3
	std y+16,R4
	std y+17,R5
	.dbline 471
; 	}
L108:
	.dbline 473
; 
; 	ncl = scl;				/* Start cluster */
	ldd R2,y+14
	ldd R3,y+15
	ldd R4,y+16
	ldd R5,y+17
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	.dbline 474
; 	for (;;) {
L116:
	.dbline 474
	.dbline 475
; 		ncl++;							/* Next cluster */
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	.dbline 476
; 		if (ncl >= mcl) {				/* Wrap around */
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	ldd R6,y+6
	ldd R7,y+7
	ldd R8,y+8
	ldd R9,y+9
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L120
X61:
	.dbline 476
	.dbline 477
; 			ncl = 2;
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+6,R20
	std y+7,R21
	std y+8,R22
	std y+9,R23
	.dbline 478
; 			if (ncl > scl) return 0;	/* No free custer */
	ldd R2,y+14
	ldd R3,y+15
	ldd R4,y+16
	ldd R5,y+17
	ldd R6,y+6
	ldd R7,y+7
	ldd R8,y+8
	ldd R9,y+9
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brsh L122
X62:
	.dbline 478
	ldi R16,0
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L106
L122:
	.dbline 479
; 		}
L120:
	.dbline 480
; 		cs = get_fat(fs, ncl);			/* Get the cluster status */
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R10
	xcall _get_fat
	std y+10,R16
	std y+11,R17
	std y+12,R18
	std y+13,R19
	.dbline 481
; 		if (cs == 0) break;				/* Found a free cluster */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L124
X63:
	.dbline 481
	xjmp L118
L124:
	.dbline 482
; 		if (cs == 0xFFFFFFFF || cs == 1)/* An error occured */
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L128
X64:
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L126
X65:
L128:
	.dbline 483
; 			return cs;
	ldd R16,y+10
	ldd R17,y+11
	ldd R18,y+12
	ldd R19,y+13
	xjmp L106
L126:
	.dbline 484
; 		if (ncl == scl) return 0;		/* No free custer */
	ldd R2,y+14
	ldd R3,y+15
	ldd R4,y+16
	ldd R5,y+17
	ldd R6,y+6
	ldd R7,y+7
	ldd R8,y+8
	ldd R9,y+9
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	breq X72
	xjmp L116
X72:
X66:
	.dbline 484
	ldi R16,0
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L106
L118:
	.dbline 487
; 	}
; 
; 	if (put_fat(fs, ncl, 0x0FFFFFFF))	/* Mark the new cluster "in use" */
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,15
	std y+2,R20
	std y+3,R21
	std y+4,R22
	std y+5,R23
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R10
	xcall _put_fat
	tst R16
	breq L131
X67:
	.dbline 488
; 		return 0xFFFFFFFF;
	ldi R16,255
	ldi R17,255
	ldi R18,255
	ldi R19,255
	xjmp L106
L131:
	.dbline 489
; 	if (clst != 0) {					/* Link it to the previous one if needed */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+30
	ldd R3,y+31
	ldd R4,y+32
	ldd R5,y+33
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L133
X68:
	.dbline 489
	.dbline 490
; 		if (put_fat(fs, clst, ncl))
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	std y+2,R2
	std y+3,R3
	std y+4,R4
	std y+5,R5
	ldd R2,y+30
	ldd R3,y+31
	ldd R4,y+32
	ldd R5,y+33
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R10
	xcall _put_fat
	tst R16
	breq L135
X69:
	.dbline 491
; 			return 0xFFFFFFFF;
	ldi R16,255
	ldi R17,255
	ldi R18,255
	ldi R19,255
	xjmp L106
L135:
	.dbline 492
; 	}
L133:
	.dbline 494
; 
; 	fs->last_clust = ncl;				/* Update FSINFO */
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	movw R30,R10
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 495
; 	if (fs->free_clust != 0xFFFFFFFF) {
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L137
X70:
	.dbline 495
	.dbline 496
; 		fs->free_clust--;
	movw R24,R30
	adiw R24,14
	movw R12,R24
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R24
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 497
; 		fs->fsi_flag = 1;
	ldi R24,1
	movw R30,R10
	std z+9,R24
	.dbline 498
; 	}
L137:
	.dbline 500
; 
; 	return ncl;		/* Return new cluster number */
	ldd R16,y+6
	ldd R17,y+7
	ldd R18,y+8
	ldd R19,y+9
	.dbline -2
L106:
	.dbline 0 ; func end
	adiw R28,22
	xcall pop_xgsetF03C
	adiw R28,2
	ret
	.dbsym l mcl 18 l
	.dbsym l scl 14 l
	.dbsym l cs 10 l
	.dbsym l ncl 6 l
	.dbsym l clst 30 l
	.dbsym r fs 10 pS[_FATFS_]
	.dbend
	.dbfunc s clust2sect _clust2sect fl
;           clst -> y+6
;             fs -> R10,R11
	.even
_clust2sect:
	st -y,r19
	st -y,r18
	xcall push_xgsetF00C
	movw R10,R16
	.dbline -1
	.dbline 516
; }
; #endif /* !_FS_READONLY */
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Get sector# from cluster#                                             */
; /*-----------------------------------------------------------------------*/
; 
; static
; DWORD clust2sect (	/* !=0: Sector number, 0: Failed - invalid cluster# */
; 	FATFS *fs,		/* File system object */
; 	DWORD clst		/* Cluster# to be converted */
; )
; {
	.dbline 517
; 	clst -= 2;
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	.dbline 518
; 	if (clst >= (fs->max_clust - 2)) return 0;		/* Invalid cluster# */
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R10
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	ldd R6,y+6
	ldd R7,y+7
	ldd R8,y+8
	ldd R9,y+9
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L140
X73:
	.dbline 518
	ldi R16,0
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L139
L140:
	.dbline 519
; 	return clst * fs->csize + fs->database;
	movw R30,R10
	ldd R2,z+2
	clr R3
	clr R4
	clr R5
	ldd R16,y+6
	ldd R17,y+7
	ldd R18,y+8
	ldd R19,y+9
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32u
	movw R2,R16
	movw R4,R18
	movw R30,R10
	ldd R6,z+38
	ldd R7,z+39
	ldd R8,z+40
	ldd R9,z+41
	add R2,R6
	adc R3,R7
	adc R4,R8
	adc R5,R9
	movw R16,R2
	movw R18,R4
	.dbline -2
L139:
	.dbline 0 ; func end
	xcall pop_xgsetF00C
	adiw R28,2
	ret
	.dbsym l clst 6 l
	.dbsym r fs 10 pS[_FATFS_]
	.dbend
	.dbfunc s dir_seek _dir_seek fc
	.dbstruct 0 22 _DIR_
	.dbfield 0 fs pS[_FATFS_]
	.dbfield 2 id s
	.dbfield 4 index s
	.dbfield 6 sclust l
	.dbfield 10 clust l
	.dbfield 14 sect l
	.dbfield 18 dir pc
	.dbfield 20 fn pc
	.dbend
;             ic -> R14,R15
;           clst -> y+2
;            idx -> R12,R13
;             dj -> R10,R11
	.even
_dir_seek:
	xcall push_xgsetF0FC
	movw R12,R18
	movw R10,R16
	sbiw R28,6
	.dbline -1
	.dbline 534
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Directory handling - Seek directory index                             */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT dir_seek (
; 	DIR *dj,		/* Pointer to directory object */
; 	WORD idx		/* Directory index number */
; )
; {
	.dbline 539
; 	DWORD clst;
; 	WORD ic;
; 
; 
; 	dj->index = idx;
	movw R30,R10
	std z+5,R13
	std z+4,R12
	.dbline 540
; 	clst = dj->sclust;
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	std y+2,R2
	std y+3,R3
	std y+4,R4
	std y+5,R5
	.dbline 541
; 	if (clst == 1 || clst >= dj->fs->max_clust)	/* Check start cluster range */
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L145
X74:
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L143
X75:
L145:
	.dbline 542
; 		return FR_INT_ERR;
	ldi R16,2
	xjmp L142
L143:
	.dbline 543
; 	if (!clst && dj->fs->fs_type == FS_FAT32)	/* Replace cluster# 0 with root cluster# if in FAT32 */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L146
X76:
	movw R30,R10
	ldd R26,z+0
	ldd R27,z+1
	ld R24,x
	cpi R24,3
	brne L146
X77:
	.dbline 544
; 		clst = dj->fs->dirbase;
	adiw R26,34
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	std y+2,R2
	std y+3,R3
	std y+4,R4
	std y+5,R5
L146:
	.dbline 546
; 
; 	if (clst == 0) {	/* Static table */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X84
	xjmp L148
X84:
X78:
	.dbline 546
	.dbline 547
; 		dj->clust = clst;
	movw R30,R10
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 548
; 		if (idx >= dj->fs->n_rootdir)		/* Index is out of range */
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,7
	ld R2,x+
	ld R3,x
	cp R12,R2
	cpc R13,R3
	brlo L150
X79:
	.dbline 549
; 			return FR_INT_ERR;
	ldi R16,2
	xjmp L142
L150:
	.dbline 550
; 		dj->sect = dj->fs->dirbase + idx / (SS(dj->fs) / 32);	/* Sector# */
	movw R2,R12
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	clr R4
	clr R5
	movw R30,R10
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,34
	ld R6,x+
	ld R7,x+
	ld R8,x+
	ld R9,x
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+14,R6
	std z+15,R7
	std z+16,R8
	std z+17,R9
	.dbline 551
; 	}
	xjmp L149
L148:
	.dbline 552
; 	else {				/* Dynamic table */
	.dbline 553
; 		ic = SS(dj->fs) / 32 * dj->fs->csize;	/* Entries per cluster */
	movw R30,R10
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R2,z+2
	ldi R24,16
	mul R24,R2
	movw R14,R0
	xjmp L153
L152:
	.dbline 554
; 		while (idx >= ic) {	/* Follow cluster chain */
	.dbline 555
; 			clst = get_fat(dj->fs, clst);				/* Get next cluster */
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R30,R10
	ldd R16,z+0
	ldd R17,z+1
	xcall _get_fat
	std y+2,R16
	std y+3,R17
	std y+4,R18
	std y+5,R19
	.dbline 556
; 			if (clst == 0xFFFFFFFF) return FR_DISK_ERR;	/* Disk error */
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L155
X80:
	.dbline 556
	ldi R16,1
	xjmp L142
L155:
	.dbline 557
; 			if (clst < 2 || clst >= dj->fs->max_clust)	/* Reached to end of table or int error */
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L159
X81:
	movw R30,R10
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L157
X82:
L159:
	.dbline 558
; 				return FR_INT_ERR;
	ldi R16,2
	xjmp L142
L157:
	.dbline 559
; 			idx -= ic;
	sub R12,R14
	sbc R13,R15
	.dbline 560
; 		}
L153:
	.dbline 554
	cp R12,R14
	cpc R13,R15
	brlo X85
	xjmp L152
X85:
X83:
	.dbline 561
; 		dj->clust = clst;
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	movw R30,R10
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 562
; 		dj->sect = clust2sect(dj->fs, clst) + idx / (SS(dj->fs) / 32);	/* Sector# */
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _clust2sect
	movw R2,R12
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	clr R4
	clr R5
	movw R6,R16
	movw R8,R18
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	movw R30,R10
	std z+14,R6
	std z+15,R7
	std z+16,R8
	std z+17,R9
	.dbline 563
; 	}
L149:
	.dbline 565
; 
; 	dj->dir = dj->fs->win + (idx % (SS(dj->fs) / 32)) * 32;	/* Ptr to the entry in the sector */
	movw R18,R12
	andi R18,15
	andi R19,0
	ldi R16,32
	ldi R17,0
	xcall empy16s
	movw R2,R16
	movw R30,R10
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,46
	add R2,R24
	adc R3,R25
	std z+19,R3
	std z+18,R2
	.dbline 567
; 
; 	return FR_OK;	/* Seek succeeded */
	clr R16
	.dbline -2
L142:
	.dbline 0 ; func end
	adiw R28,6
	xjmp pop_xgsetF0FC
	.dbsym r ic 14 s
	.dbsym l clst 2 l
	.dbsym r idx 12 s
	.dbsym r dj 10 pS[_DIR_]
	.dbend
	.dbfunc s dir_next _dir_next fc
;              c -> R10
;           clst -> y+2
;              i -> R12,R13
;        streach -> R10
;             dj -> y+16
	.even
_dir_next:
	xcall push_arg4
	xcall push_xgsetF0FC
	mov R10,R18
	sbiw R28,6
	.dbline -1
	.dbline 582
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Directory handling - Move directory index next                        */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT dir_next (	/* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT and could not streach */
; 	DIR *dj,		/* Pointer to directory object */
; 	BOOL streach	/* FALSE: Do not streach table, TRUE: Streach table if needed */
; )
; {
	.dbline 587
; 	DWORD clst;
; 	WORD i;
; 
; 
; 	i = dj->index + 1;
	ldd R30,y+16
	ldd R31,y+17
	ldd R24,z+4
	ldd R25,z+5
	adiw R24,1
	movw R12,R24
	.dbline 588
; 	if (!i || !dj->sect)	/* Report EOT when index has reached 65535 */
	cpi R24,0
	cpc R24,R25
	breq L163
X86:
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L161
X87:
L163:
	.dbline 589
; 		return FR_NO_FILE;
	ldi R16,4
	xjmp L160
L161:
	.dbline 591
; 
; 	if (!(i % (SS(dj->fs) / 32))) {	/* Sector changed? */
	movw R24,R12
	andi R24,15
	andi R25,0
	cpi R24,0
	cpc R24,R25
	breq X102
	xjmp L164
X102:
X88:
	.dbline 591
	.dbline 592
; 		dj->sect++;					/* Next sector */
	ldd R24,y+16
	ldd R25,y+17
	adiw R24,14
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R24
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 594
; 
; 		if (dj->clust == 0) {	/* Static table */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R30,y+16
	ldd R31,y+17
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L166
X89:
	.dbline 594
	.dbline 595
; 			if (i >= dj->fs->n_rootdir)	/* Report EOT when end of table */
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,7
	ld R2,x+
	ld R3,x
	cp R12,R2
	cpc R13,R3
	brsh X103
	xjmp L167
X103:
X90:
	.dbline 596
; 				return FR_NO_FILE;
	ldi R16,4
	xjmp L160
L166:
	.dbline 598
; 		}
; 		else {					/* Dynamic table */
	.dbline 599
; 			if (((i / (SS(dj->fs) / 32)) & (dj->fs->csize - 1)) == 0) {	/* Cluster changed? */
	ldd R30,y+16
	ldd R31,y+17
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R24,z+2
	clr R25
	sbiw R24,1
	movw R2,R12
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	and R2,R24
	and R3,R25
	tst R2
	breq X104
	xjmp L170
X104:
	tst R3
	breq X105
	xjmp L170
X105:
X91:
	.dbline 599
	.dbline 600
; 				clst = get_fat(dj->fs, dj->clust);				/* Get next cluster */
	ldd R30,y+16
	ldd R31,y+17
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _get_fat
	std y+2,R16
	std y+3,R17
	std y+4,R18
	std y+5,R19
	.dbline 601
; 				if (clst <= 1) return FR_INT_ERR;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R20,R2
	cpc R21,R3
	cpc R22,R4
	cpc R23,R5
	brlo L172
X92:
	.dbline 601
	ldi R16,2
	xjmp L160
L172:
	.dbline 602
; 				if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L174
X93:
	.dbline 602
	ldi R16,1
	xjmp L160
L174:
	.dbline 603
; 				if (clst >= dj->fs->max_clust) {				/* When it reached end of dynamic table */
	ldd R30,y+16
	ldd R31,y+17
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R6,y+2
	ldd R7,y+3
	ldd R8,y+4
	ldd R9,y+5
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh X106
	xjmp L176
X106:
X94:
	.dbline 603
	.dbline 606
; #if !_FS_READONLY
; 					BYTE c;
; 					if (!streach) return FR_NO_FILE;			/* When do not streach, report EOT */
	tst R10
	brne L178
X95:
	.dbline 606
	ldi R16,4
	xjmp L160
L178:
	.dbline 607
; 					clst = create_chain(dj->fs, dj->clust);		/* Streach cluster chain */
	ldd R30,y+16
	ldd R31,y+17
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _create_chain
	std y+2,R16
	std y+3,R17
	std y+4,R18
	std y+5,R19
	.dbline 608
; 					if (clst == 0) return FR_DENIED;			/* No free cluster */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L180
X96:
	.dbline 608
	ldi R16,7
	xjmp L160
L180:
	.dbline 609
; 					if (clst == 1) return FR_INT_ERR;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L182
X97:
	.dbline 609
	ldi R16,2
	xjmp L160
L182:
	.dbline 610
; 					if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L184
X98:
	.dbline 610
	ldi R16,1
	xjmp L160
L184:
	.dbline 612
; 					/* Clean-up streached table */
; 					if (move_window(dj->fs, 0)) return FR_DISK_ERR;	/* Flush active window */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldd R30,y+16
	ldd R31,y+17
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	tst R16
	breq L186
X99:
	.dbline 612
	ldi R16,1
	xjmp L160
L186:
	.dbline 613
; 					mem_set(dj->fs->win, 0, SS(dj->fs));			/* Clear window buffer */
	ldi R24,512
	ldi R25,2
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	ldd R30,y+16
	ldd R31,y+17
	ldd R16,z+0
	ldd R17,z+1
	subi R16,210  ; offset = 46
	sbci R17,255
	xcall _mem_set
	.dbline 614
; 					dj->fs->winsect = clust2sect(dj->fs, clst);	/* Cluster start sector */
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R30,y+16
	ldd R31,y+17
	ldd R10,z+0
	ldd R11,z+1
	movw R16,R10
	xcall _clust2sect
	movw R30,R10
	std z+42,R16
	std z+43,R17
	std z+44,R18
	std z+45,R19
	.dbline 615
; 					for (c = 0; c < dj->fs->csize; c++) {		/* Fill the new cluster with 0 */
	clr R10
	xjmp L191
L188:
	.dbline 615
	.dbline 616
; 						dj->fs->wflag = 1;
	ldi R24,1
	ldd R30,y+16
	ldd R31,y+17
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	std z+4,R24
	.dbline 617
; 						if (move_window(dj->fs, 0)) return FR_DISK_ERR;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldd R30,y+16
	ldd R31,y+17
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R14,R16
	tst R16
	breq L192
X100:
	.dbline 617
	ldi R16,1
	xjmp L160
L192:
	.dbline 618
; 						dj->fs->winsect++;
	ldd R30,y+16
	ldd R31,y+17
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,42
	movw R14,R24
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R24
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 619
; 					}
L189:
	.dbline 615
	inc R10
L191:
	.dbline 615
	ldd R30,y+16
	ldd R31,y+17
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R2,z+2
	cp R10,R2
	brsh X107
	xjmp L188
X107:
X101:
	.dbline 620
; 					dj->fs->winsect -= c;						/* Rewind window address */
	ldd R30,y+16
	ldd R31,y+17
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,42
	movw R14,R24
	mov R2,R10
	clr R3
	clr R4
	clr R5
	movw R30,R24
	ldd R6,z+0
	ldd R7,z+1
	ldd R8,z+2
	ldd R9,z+3
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	std z+0,R6
	std z+1,R7
	std z+2,R8
	std z+3,R9
	.dbline 624
; #else
; 					return FR_NO_FILE;			/* Report EOT */
; #endif
; 				}
L176:
	.dbline 625
; 				dj->clust = clst;				/* Initialize data for new cluster */
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	ldd R30,y+16
	ldd R31,y+17
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 626
; 				dj->sect = clust2sect(dj->fs, clst);
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _clust2sect
	ldd R30,y+16
	ldd R31,y+17
	std z+14,R16
	std z+15,R17
	std z+16,R18
	std z+17,R19
	.dbline 627
; 			}
L170:
	.dbline 628
; 		}
L167:
	.dbline 629
; 	}
L164:
	.dbline 631
; 
; 	dj->index = i;
	ldd R30,y+16
	ldd R31,y+17
	std z+5,R13
	std z+4,R12
	.dbline 632
; 	dj->dir = dj->fs->win + (i % (SS(dj->fs) / 32)) * 32;
	movw R18,R12
	andi R18,15
	andi R19,0
	ldi R16,32
	ldi R17,0
	xcall empy16s
	movw R2,R16
	ldd R30,y+16
	ldd R31,y+17
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,46
	add R2,R24
	adc R3,R25
	std z+19,R3
	std z+18,R2
	.dbline 634
; 
; 	return FR_OK;
	clr R16
	.dbline -2
L160:
	.dbline 0 ; func end
	adiw R28,6
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym r c 10 c
	.dbsym l clst 2 l
	.dbsym r i 12 s
	.dbsym r streach 10 c
	.dbsym l dj 16 pS[_DIR_]
	.dbend
	.dbfunc s dir_find _dir_find fc
;              c -> R12
;            dir -> R10,R11
;            res -> R20
;             dj -> R22,R23
	.even
_dir_find:
	xcall push_xgsetF03C
	movw R22,R16
	sbiw R28,2
	.dbline -1
	.dbline 807
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry   */
; /*-----------------------------------------------------------------------*/
; #if _USE_LFN
; static
; const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};	/* Offset of LFN chars in the directory entry */
; 
; 
; static
; bool cmp_lfn (			/* TRUE:Matched, FALSE:Not matched */
; 	WCHAR *lfnbuf,		/* Pointer to the LFN to be compared */
; 	BYTE *dir			/* Pointer to the directory entry containing a part of LFN */
; )
; {
; 	int i, s;
; 	WCHAR wc;
; 
; 
; 	i = ((dir[LDIR_Ord] & 0xBF) - 1) * 13;	/* Get offset in the LFN buffer */
; 	s = 0;
; 	do {
; 		wc = ff_wtoupper(LD_WORD(dir+LfnOfs[s]));	/* Get an LFN character */
; 		if (i >= _MAX_LFN || wc != ff_wtoupper(lfnbuf[i++]))	/* Compare it with the reference character */
; 			return FALSE;
; 	} while (++s < 13 && wc);		/* Repeat until all chars in the entry or a NUL char is processed */
; 
; 	return TRUE;					/* The LFN entry matched */
; }
; 
; 
; 
; static
; bool pick_lfn (			/* TRUE:Succeeded, FALSE:Buffer overflow */
; 	WCHAR *lfnbuf,		/* Pointer to the Unicode-LFN buffer */
; 	BYTE *dir			/* Pointer to the directory entry */
; )
; {
; 	int i, s;
; 	WCHAR wc;
; 
; 
; 	i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13;	/* Offset in the LFN buffer */
; 
; 	s = 0;
; 	do {
; 		if (i >= _MAX_LFN) return FALSE;	/* Buffer overflow? */
; 		wc = LD_WORD(dir+LfnOfs[s]);		/* Get an LFN char */
; 		if (!wc) break;						/* End of LFN? */
; 		lfnbuf[i++] = wc;					/* Store it */
; 	} while (++s < 13);						/* Repeat until last char is copied */
; 
; 	if (dir[LDIR_Ord] & 0x40) {				/* Put terminator if it is the last LFN part */
; 		if (i >= _MAX_LFN) return FALSE;	/* Buffer overflow? */
; 		lfnbuf[i] = 0;
; 	}
; 
; 	return TRUE;
; }
; 
; 
; #if !_FS_READONLY
; static
; void fit_lfn (
; 	const WCHAR *lfnbuf,	/* Pointer to the LFN buffer */
; 	BYTE *dir,				/* Pointer to the directory entry */
; 	BYTE ord,				/* LFN order (1-20) */
; 	BYTE sum				/* SFN sum */
; )
; {
; 	int i, s;
; 	WCHAR wc;
; 
; 
; 	dir[LDIR_Chksum] = sum;			/* Set check sum */
; 	dir[LDIR_Attr] = AM_LFN;		/* Set attribute. LFN entry */
; 	dir[LDIR_Type] = 0;
; 	ST_WORD(dir+LDIR_FstClusLO, 0);
; 
; 	i = (ord - 1) * 13;				/* Get offset in the LFN buffer */
; 	s = wc = 0;
; 	do {
; 		if (wc != 0xFFFF) wc = lfnbuf[i++];	/* Get an effective char */
; 		ST_WORD(dir+LfnOfs[s], wc);	/* Put it */
; 		if (!wc) wc = 0xFFFF;		/* Padding chars following last char */
; 	} while (++s < 13);
; 	if (wc == 0xFFFF || !lfnbuf[i]) ord |= 0x40;	/* Bottom LFN part is the start of LFN sequence */
; 	dir[LDIR_Ord] = ord;			/* Set the LFN order */
; }
; 
; #endif
; #endif
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Create numbered name                                                  */
; /*-----------------------------------------------------------------------*/
; #if _USE_LFN
; void gen_numname (
; 	BYTE *dst,			/* Pointer to genartated SFN */
; 	const BYTE *src,	/* Pointer to source SFN to be modified */
; 	const WCHAR *lfn,	/* Pointer to LFN */
; 	WORD num			/* Sequense number */
; )
; {
; 	char ns[8];
; 	int i, j;
; 
; 
; 	mem_cpy(dst, src, 11);
; 
; 	if (num > 5) {	/* On many collisions, generate a hash number instead of sequencial number */
; 		do num = (num >> 1) + (num << 15) + (WORD)*lfn++; while (*lfn);
; 	}
; 
; 	/* itoa */
; 	i = 7;
; 	do {
; 		ns[i--] = (num % 10) + '0';
; 		num /= 10;
; 	} while (num);
; 	ns[i] = '~';
; 
; 	/* Append the number */
; 	for (j = 0; j < i && dst[j] != ' '; j++) {
; 		if (IsDBCS1(dst[j])) {
; 			if (j == i - 1) break;
; 			j++;
; 		}
; 	}
; 	do {
; 		dst[j++] = (i < 8) ? ns[i++] : ' ';
; 	} while (j < 8);
; }
; #endif
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Calculate sum of an SFN                                               */
; /*-----------------------------------------------------------------------*/
; #if _USE_LFN
; static
; BYTE sum_sfn (
; 	const BYTE *dir		/* Ptr to directory entry */
; )
; {
; 	BYTE sum = 0;
; 	int n = 11;
; 
; 	do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n);
; 	return sum;
; }
; #endif
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Directory handling - Find an object in the directory                  */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT dir_find (
; 	DIR *dj			/* Pointer to the directory object linked to the file name */
; )
; {
	.dbline 814
; 	FRESULT res;
; 	BYTE c, *dir;
; #if _USE_LFN
; 	BYTE a, lfen, ord, sum;
; #endif
; 
; 	res = dir_seek(dj, 0);			/* Rewind directory object */
	clr R18
	clr R19
	movw R16,R22
	xcall _dir_seek
	mov R20,R16
	.dbline 815
; 	if (res != FR_OK) return res;
	tst R16
	breq L195
X108:
	.dbline 815
	xjmp L194
L195:
L197:
	.dbline 820
; 
; #if _USE_LFN
; 	ord = sum = 0xFF; lfen = *(dj->fn+11) & NS_LOSS;
; #endif
; 	do {
	.dbline 821
; 		res = move_window(dj->fs, dj->sect);
	movw R30,R22
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R20,R16
	.dbline 822
; 		if (res != FR_OK) break;
	tst R16
	breq L200
X109:
	.dbline 822
	xjmp L199
L200:
	.dbline 823
; 		dir = dj->dir;					/* Ptr to the directory entry of current index */
	movw R30,R22
	ldd R10,z+18
	ldd R11,z+19
	.dbline 824
; 		c = dir[DIR_Name];
	movw R30,R10
	ldd R12,z+0
	.dbline 825
; 		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
	tst R12
	brne L202
X110:
	.dbline 825
	.dbline 825
	ldi R20,4
	.dbline 825
	xjmp L199
L202:
	.dbline 853
; #if _USE_LFN	/* LFN configuration */
; 		a = dir[DIR_Attr] & AM_MASK;
; 		if (c == 0xE5 || ((a & AM_VOL) && a != AM_LFN)) {	/* An entry without valid data */
; 			ord = 0xFF;
; 		} else {
; 			if (a == AM_LFN) {			/* An LFN entry is found */
; 				if (dj->lfn) {
; 					if (c & 0x40) {		/* Is it start of LFN sequence? */
; 						sum = dir[LDIR_Chksum];
; 						c &= 0xBF; ord = c;		/* LFN start order */
; 						dj->lfn_idx = dj->index;
; 					}
; 					/* Check LFN validity. Compare LFN if it is out of 8.3 format */
; 					ord = (c == ord && sum == dir[LDIR_Chksum] && (!lfen || cmp_lfn(dj->lfn, dir))) ? ord - 1 : 0xFF;
; 				}
; 			} else {					/* An SFN entry is found */
; 				if (ord || sum != sum_sfn(dir))	/* Did not LFN match? */
; 					dj->lfn_idx = 0xFFFF;
; 				if (lfen) {				/* Match LFN if it is out of 8.3 format */
; 					if (ord == 0) break;
; 				} else {				/* Match SFN if LFN is in 8.3 format */
; 					if (!mem_cmp(dir, dj->fn, 11)) break;
; 				}
; 				ord = 0xFF;
; 			}
; 		}
; #else		/* Non LFN configuration */
; 		if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */
	movw R30,R10
	ldd R2,z+11
	sbrc R2,3
	rjmp L204
X111:
	ldi R24,11
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R30,R22
	ldd R18,z+20
	ldd R19,z+21
	movw R16,R10
	xcall _mem_cmp
	movw R10,R16
	cpi R16,0
	cpc R16,R17
	brne L204
X112:
	.dbline 854
; 			break;
	xjmp L199
L204:
	.dbline 856
; #endif
; 		res = dir_next(dj, FALSE);				/* Next entry */
	clr R18
	movw R16,R22
	xcall _dir_next
	mov R10,R16
	mov R20,R10
	.dbline 857
; 	} while (res == FR_OK);
L198:
	.dbline 857
	tst R20
	brne X114
	xjmp L197
X114:
X113:
L199:
	.dbline 859
; 
; 	return res;
	mov R16,R20
	.dbline -2
L194:
	.dbline 0 ; func end
	adiw R28,2
	xjmp pop_xgsetF03C
	.dbsym r c 12 c
	.dbsym r dir 10 pc
	.dbsym r res 20 c
	.dbsym r dj 22 pS[_DIR_]
	.dbend
	.dbfunc s dir_read _dir_read fc
;            dir -> R10,R11
;              c -> R12
;            res -> R20
;             dj -> R22,R23
	.even
_dir_read:
	xcall push_xgsetF03C
	movw R22,R16
	sbiw R28,2
	.dbline -1
	.dbline 873
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Read an object from the directory                                     */
; /*-----------------------------------------------------------------------*/
; #if _FS_MINIMIZE <= 1
; static
; FRESULT dir_read (
; 	DIR *dj			/* Pointer to the directory object that pointing the entry to be read */
; )
; {
	.dbline 880
; 	FRESULT res;
; 	BYTE c, *dir;
; #if _USE_LFN
; 	BYTE a, ord = 0xFF, sum = 0xFF;
; #endif
; 
; 	res = FR_NO_FILE;
	ldi R20,4
	xjmp L208
L207:
	.dbline 881
; 	while (dj->sect) {
	.dbline 882
; 		res = move_window(dj->fs, dj->sect);
	movw R30,R22
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R20,R16
	.dbline 883
; 		if (res != FR_OK) break;
	tst R16
	breq L210
X115:
	.dbline 883
	xjmp L209
L210:
	.dbline 884
; 		dir = dj->dir;					/* Ptr to the directory entry of current index */
	movw R30,R22
	ldd R10,z+18
	ldd R11,z+19
	.dbline 885
; 		c = dir[DIR_Name];
	movw R30,R10
	ldd R12,z+0
	.dbline 886
; 		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
	tst R12
	brne L212
X116:
	.dbline 886
	.dbline 886
	ldi R20,4
	.dbline 886
	xjmp L209
L212:
	.dbline 907
; #if _USE_LFN	/* LFN configuration */
; 		a = dir[DIR_Attr] & AM_MASK;
; 		if (c == 0xE5 || (!_FS_RPATH && c == '.') || ((a & AM_VOL) && a != AM_LFN)) {	/* An entry without valid data */
; 			ord = 0xFF;
; 		} else {
; 			if (a == AM_LFN) {			/* An LFN entry is found */
; 				if (c & 0x40) {			/* Is it start of LFN sequence? */
; 					sum = dir[LDIR_Chksum];
; 					c &= 0xBF; ord = c;
; 					dj->lfn_idx = dj->index;
; 				}
; 				/* Check LFN validity and capture it */
; 				ord = (c == ord && sum == dir[LDIR_Chksum] && pick_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF;
; 			} else {					/* An SFN entry is found */
; 				if (ord || sum != sum_sfn(dir))	/* Is there a valid LFN entry? */
; 					dj->lfn_idx = 0xFFFF;		/* No LFN. */
; 				break;
; 			}
; 		}
; #else		/* Non LFN configuration */
; 		if (c != 0xE5 && (_FS_RPATH || c != '.') && !(dir[DIR_Attr] & AM_VOL))	/* Is it a valid entry? */
	mov R24,R12
	cpi R24,229
	breq L214
X117:
	cpi R24,46
	breq L214
X118:
	movw R30,R10
	ldd R2,z+11
	sbrc R2,3
	rjmp L214
X119:
	.dbline 908
; 			break;
	xjmp L209
L214:
	.dbline 910
; #endif
; 		res = dir_next(dj, FALSE);				/* Next entry */
	clr R18
	movw R16,R22
	xcall _dir_next
	mov R20,R16
	.dbline 911
; 		if (res != FR_OK) break;
	tst R16
	breq L216
X120:
	.dbline 911
	xjmp L209
L216:
	.dbline 912
; 	}
L208:
	.dbline 881
	ldi R24,0
	ldi R25,0
	ldi R26,0
	ldi R27,0
	movw R30,R22
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	cp R2,R24
	cpc R3,R25
	cpc R4,R26
	cpc R5,R27
	breq X123
	xjmp L207
X123:
X121:
L209:
	.dbline 914
; 
; 	if (res != FR_OK) dj->sect = 0;
	tst R20
	breq L218
X122:
	.dbline 914
	ldi R24,0
	ldi R25,0
	ldi R26,0
	ldi R27,0
	movw R30,R22
	std z+14,R24
	std z+15,R25
	std z+16,R26
	std z+17,R27
L218:
	.dbline 916
; 
; 	return res;
	mov R16,R20
	.dbline -2
L206:
	.dbline 0 ; func end
	adiw R28,2
	xjmp pop_xgsetF03C
	.dbsym r dir 10 pc
	.dbsym r c 12 c
	.dbsym r res 20 c
	.dbsym r dj 22 pS[_DIR_]
	.dbend
	.dbfunc s dir_register _dir_register fc
;            dir -> R22,R23
;              c -> R22
;            res -> R10
;             dj -> R20,R21
	.even
_dir_register:
	xcall push_xgsetF03C
	movw R20,R16
	sbiw R28,2
	.dbline -1
	.dbline 930
; }
; #endif
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Register an object to the directory                                   */
; /*-----------------------------------------------------------------------*/
; #if !_FS_READONLY
; static
; FRESULT dir_register (	/* FR_OK:Successful, FR_DENIED:No free entry or too many SFN collision, FR_DISK_ERR:Disk error */
; 	DIR *dj				/* Target directory with object name to be created */
; )
; {
	.dbline 996
; 	FRESULT res;
; 	BYTE c, *dir;
; #if _USE_LFN	/* LFN configuration */
; 	WORD n, ne, is;
; 	BYTE sn[12], *fn, sum;
; 	WCHAR *lfn;
; 
; 
; 	fn = dj->fn; lfn = dj->lfn;
; 	mem_cpy(sn, fn, 12);
; 
; 	if (_FS_RPATH && (sn[11] & NS_DOT)) return FR_INVALID_NAME;	/* Cannot create dot entry */
; 
; 	if (sn[11] & NS_LOSS) {			/* When LFN is out of 8.3 format, generate a numbered name */
; 		fn[11] = 0; dj->lfn = NULL;			/* Find only SFN */
; 		for (n = 1; n < 100; n++) {
; 			gen_numname(fn, sn, lfn, n);	/* Generate a numbered name */
; 			res = dir_find(dj);				/* Check if the name collides with existing SFN */
; 			if (res != FR_OK) break;
; 		}
; 		if (n == 100) return FR_DENIED;		/* Abort if too many collisions */
; 		if (res != FR_NO_FILE) return res;	/* Abort if the result is other than 'not collided' */
; 		fn[11] = sn[11]; dj->lfn = lfn;
; 	}
; 
; 	if (sn[11] & NS_LFN) {			/* When LFN is to be created, reserve reserve an SFN + LFN entries. */
; 		for (ne = 0; lfn[ne]; ne++) ;
; 		ne = (ne + 25) / 13;
; 	} else {						/* Otherwise reserve only an SFN entry. */
; 		ne = 1;
; 	}
; 
; 	/* Reserve contiguous entries */
; 	res = dir_seek(dj, 0);
; 	if (res != FR_OK) return res;
; 	n = is = 0;
; 	do {
; 		res = move_window(dj->fs, dj->sect);
; 		if (res != FR_OK) break;
; 		c = *dj->dir;				/* Check the entry status */
; 		if (c == 0xE5 || c == 0) {	/* Is it a blank entry? */
; 			if (n == 0) is = dj->index;	/* First index of the contigulus entry */
; 			if (++n == ne) break;	/* A contiguous entry that requiered count is found */
; 		} else {
; 			n = 0;					/* Not a blank entry. Restart to search */
; 		}
; 		res = dir_next(dj, TRUE);	/* Next entry with table streach */
; 	} while (res == FR_OK);
; 
; 	if (res == FR_OK && ne > 1) {	/* Initialize LFN entry if needed */
; 		res = dir_seek(dj, is);
; 		if (res == FR_OK) {
; 			sum = sum_sfn(dj->fn);	/* Sum of the SFN tied to the LFN */
; 			ne--;
; 			do {					/* Store LFN entries in bottom first */
; 				res = move_window(dj->fs, dj->sect);
; 				if (res != FR_OK) break;
; 				fit_lfn(dj->lfn, dj->dir, (BYTE)ne, sum);
; 				dj->fs->wflag = 1;
; 				res = dir_next(dj, FALSE);	/* Next entry */
; 			} while (res == FR_OK && --ne);
; 		}
; 	}
; 
; #else	/* Non LFN configuration */
; 	res = dir_seek(dj, 0);
	clr R18
	clr R19
	movw R16,R20
	xcall _dir_seek
	mov R10,R16
	.dbline 997
; 	if (res == FR_OK) {
	tst R16
	brne L221
X124:
	.dbline 997
L223:
	.dbline 998
; 		do {	/* Find a blank entry for the SFN */
	.dbline 999
; 			res = move_window(dj->fs, dj->sect);
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R10,R16
	.dbline 1000
; 			if (res != FR_OK) break;
	tst R16
	breq L226
X125:
	.dbline 1000
	xjmp L225
L226:
	.dbline 1001
; 			c = *dj->dir;
	movw R30,R20
	ldd R26,z+18
	ldd R27,z+19
	ld R22,x
	.dbline 1002
; 			if (c == 0xE5 || c == 0) break;	/* Is it a blank entry? */
	cpi R22,229
	breq L230
X126:
	tst R22
	brne L228
X127:
L230:
	.dbline 1002
	xjmp L225
L228:
	.dbline 1003
; 			res = dir_next(dj, TRUE);		/* Next entry with table streach */
	ldi R18,1
	movw R16,R20
	xcall _dir_next
	mov R12,R16
	mov R10,R12
	.dbline 1004
; 		} while (res == FR_OK);
L224:
	.dbline 1004
	tst R10
	breq L223
X128:
L225:
	.dbline 1005
; 	}
L221:
	.dbline 1008
; #endif
; 
; 	if (res == FR_OK) {		/* Initialize the SFN entry */
	tst R10
	breq X131
	xjmp L231
X131:
X129:
	.dbline 1008
	.dbline 1009
; 		res = move_window(dj->fs, dj->sect);
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R12,R16
	mov R10,R12
	.dbline 1010
; 		if (res == FR_OK) {
	tst R16
	breq X132
	xjmp L233
X132:
X130:
	.dbline 1010
	.dbline 1011
; 			dir = dj->dir;
	movw R30,R20
	ldd R22,z+18
	ldd R23,z+19
	.dbline 1012
; 			mem_set(dir, 0, 32);		/* Clean the entry */
	ldi R24,32
	ldi R25,0
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	movw R16,R22
	xcall _mem_set
	.dbline 1013
; 			mem_cpy(dir, dj->fn, 11);	/* Put SFN */
	ldi R24,11
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R30,R20
	ldd R18,z+20
	ldd R19,z+21
	movw R16,R22
	xcall _mem_cpy
	.dbline 1014
; 			dir[DIR_NTres] = *(dj->fn+11) & 0x18;	/* Put NT flag */
	movw R30,R20
	push R26
	push R27
	ldd R26,z+20
	ldd R27,z+21
	movw R30,R26
	pop R27
	pop R26
	ldd R24,z+11
	andi R24,24
	movw R30,R22
	std z+12,R24
	.dbline 1015
; 			dj->fs->wflag = 1;
	ldi R24,1
	movw R30,R20
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	std z+4,R24
	.dbline 1016
; 		}
L233:
	.dbline 1017
; 	}
L231:
	.dbline 1019
; 
; 	return res;
	mov R16,R10
	.dbline -2
L220:
	.dbline 0 ; func end
	adiw R28,2
	xjmp pop_xgsetF03C
	.dbsym r dir 22 pc
	.dbsym r c 22 c
	.dbsym r res 10 c
	.dbsym r dj 20 pS[_DIR_]
	.dbend
	.dbfunc s dir_remove _dir_remove fc
;            res -> R10
;             dj -> R20,R21
	.even
_dir_remove:
	xcall push_xgset300C
	movw R20,R16
	sbiw R28,2
	.dbline -1
	.dbline 1034
; }
; #endif /* !_FS_READONLY */
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Remove an object from the directory                                   */
; /*-----------------------------------------------------------------------*/
; #if !_FS_READONLY && !_FS_MINIMIZE
; static
; FRESULT dir_remove (	/* FR_OK: Successful, FR_DISK_ERR: A disk error */
; 	DIR *dj				/* Directory object pointing the entry to be removed */
; )
; {
	.dbline 1054
; 	FRESULT res;
; #if _USE_LFN	/* LFN configuration */
; 	WORD i;
; 
; 	i = dj->index;	/* SFN index */
; 	res = dir_seek(dj, (WORD)((dj->lfn_idx == 0xFFFF) ? i : dj->lfn_idx));	/* Goto the SFN or top of the LFN entries */
; 	if (res == FR_OK) {
; 		do {
; 			res = move_window(dj->fs, dj->sect);
; 			if (res != FR_OK) break;
; 			*dj->dir = 0xE5;			/* Mark the entry "deleted" */
; 			dj->fs->wflag = 1;
; 			if (dj->index >= i) break;	/* When reached SFN, all entries of the object has been deleted. */
; 			res = dir_next(dj, FALSE);	/* Next entry */
; 		} while (res == FR_OK);
; 		if (res == FR_NO_FILE) res = FR_INT_ERR;
; 	}
; 
; #else			/* Non LFN configuration */
; 	res = dir_seek(dj, dj->index);
	movw R30,R20
	ldd R18,z+4
	ldd R19,z+5
	movw R16,R30
	xcall _dir_seek
	mov R10,R16
	.dbline 1055
; 	if (res == FR_OK) {
	tst R16
	brne L236
X133:
	.dbline 1055
	.dbline 1056
; 		res = move_window(dj->fs, dj->sect);
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R10,R16
	.dbline 1057
; 		if (res == FR_OK) {
	tst R16
	brne L238
X134:
	.dbline 1057
	.dbline 1058
; 			*dj->dir = 0xE5;			/* Mark the entry "deleted" */
	ldi R24,229
	movw R30,R20
	ldd R26,z+18
	ldd R27,z+19
	st x,R24
	.dbline 1059
; 			dj->fs->wflag = 1;
	ldi R24,1
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	std z+4,R24
	.dbline 1060
; 		}
L238:
	.dbline 1061
; 	}
L236:
	.dbline 1064
; #endif
; 
; 	return res;
	mov R16,R10
	.dbline -2
L235:
	.dbline 0 ; func end
	adiw R28,2
	xjmp pop_xgset300C
	.dbsym r res 10 c
	.dbsym r dj 20 pS[_DIR_]
	.dbend
	.dbfunc s create_name _create_name fc
;              p -> R22,R23
;             si -> y+7
;              b -> y+6
;            sfn -> y+4
;             ni -> R12,R13
;              i -> y+2
;              d -> R14
;              c -> R20
;           path -> y+19
;             dj -> R20,R21
	.even
_create_name:
	st -y,r19
	st -y,r18
	xcall push_xgsetF0FC
	movw R20,R16
	sbiw R28,9
	.dbline -1
	.dbline 1081
; }
; #endif /* !_FS_READONLY */
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Pick a segment and create the object name in directory form           */
; /*-----------------------------------------------------------------------*/
; 
; 
; static
; FRESULT create_name (
; 	DIR *dj,			/* Pointer to the directory object */
; 	const XCHAR **path	/* Pointer to pointer to the segment in the path string */
; )
; {
	.dbline 1210
; #ifdef _EXCVT
; 	static const BYTE cvt[] = _EXCVT;
; #endif
; #if _USE_LFN	/* LFN configuration */
; 	BYTE b, cf;
; 	WCHAR w, *lfn;
; 	int i, ni, si, di;
; 	const XCHAR *p;
; 
; 	/* Create LFN in Unicode */
; 	si = di = 0;
; 	p = *path;
; 	lfn = dj->lfn;
; 	for (;;) {
; 		w = p[si++];					/* Get a character */
; 		if (w < L' ' || w == L'/' || w == L'\\') break;	/* Break on end of segment */
; 		if (di >= _MAX_LFN)				/* Reject too long name */
; 			return FR_INVALID_NAME;
; #if !_LFN_UNICODE
; 		w &= 0xFF;
; 		if (IsDBCS1(w)) {				/* If it is a DBC 1st byte */
; 			BYTE c = p[si++];			/* Get 2nd byte */
; 			if (!IsDBCS2(c))			/* Reject invalid code for DBC */
; 				return FR_INVALID_NAME;
; 			w = (w << 8) + c;
; 		}
; 		w = ff_convert(w, 1);			/* Convert OEM to Unicode */
; 		if (!w) return FR_INVALID_NAME;	/* Reject invalid code */
; #endif
; 		if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) /* Reject unallowable chars for LFN */
; 			return FR_INVALID_NAME;
; 		lfn[di++] = w;					/* Store the Unicode char */
; 	}
; 	*path = &p[si];						/* Rerurn pointer to the next segment */
; 	cf = (w < L' ') ? NS_LAST : 0;		/* Set last segment flag if end of path */
; #if _FS_RPATH
; 	if ((di == 1 && lfn[di - 1] == L'.') || /* Is this a dot entry? */
; 		(di == 2 && lfn[di - 1] == L'.' && lfn[di - 2] == L'.')) {
; 		lfn[di] = 0;
; 		for (i = 0; i < 11; i++)
; 			dj->fn[i] = (i < di) ? '.' : ' ';
; 		dj->fn[i] = cf | NS_DOT;		/* This is a dot entry */
; 		return FR_OK;
; 	}
; #endif
; 	while (di) {						/* Strip trailing spaces and dots */
; 		w = lfn[di - 1];
; 		if (w != L' ' && w != L'.') break;
; 		di--;
; 	}
; 	if (!di) return FR_INVALID_NAME;	/* Reject null string */
; 
; 	lfn[di] = 0;						/* LFN is created */
; 
; 	/* Create SFN in directory form */
; 	mem_set(dj->fn, ' ', 11);
; 	for (si = 0; lfn[si] == L' ' || lfn[si] == L'.'; si++) ;	/* Strip leading spaces and dots */
; 	if (si) cf |= NS_LOSS | NS_LFN;
; 	while (di && lfn[di - 1] != '.') di--;	/* Find extension (di<=si: no extension) */
; 
; 	b = i = 0; ni = 8;
; 	for (;;) {
; 		w = lfn[si++];					/* Get an LFN char */
; 		if (!w) break;					/* Break when enf of the LFN */
; 		if (w == L' ' || (w == L'.' && si != di)) {	/* Remove spaces and dots */
; 			cf |= NS_LOSS | NS_LFN; continue;
; 		}
; 
; 		if (i >= ni || si == di) {		/* Extension or end of SFN */
; 			if (ni == 11) {				/* Long extension */
; 				cf |= NS_LOSS | NS_LFN; break;
; 			}
; 			if (si != di) cf |= NS_LOSS | NS_LFN;	/* File name is longer than 8 bytes */
; 			if (si > di) break;			/* No extension */
; 			si = di; i = 8; ni = 11;	/* Enter extension section */
; 			b <<= 2; continue;
; 		}
; 
; 		if (w >= 0x80) {				/* Non ASCII char */
; #ifdef _EXCVT
; 			w = ff_convert(w, 0);		/* Unicode -> OEM code */
; 			if (w) w = cvt[w - 0x80];	/* Convert extend char (SBCS) */
; #else
; 			w = ff_convert(ff_wtoupper(w), 0);	/* Unicode (Caps) -> OEM code */
; #endif
; 			cf |= NS_LFN;				/* Force create an LFN */
; 		}
; 
; 		if (_DF1S && w >= 0x100) {		/* Double byte char */
; 			if (i >= ni - 1) {
; 				cf |= NS_LOSS | NS_LFN; i = ni; continue;
; 			}
; 			dj->fn[i++] = (BYTE)(w >> 8);
; 		} else {						/* Single byte char */
; 			if (!w || chk_chr("+,;[=]", w)) {	/* Replace unallowable chars for SFN */
; 				w = '_'; cf |= NS_LOSS | NS_LFN;	/* Lossy conversion */
; 			} else {
; 				if (IsUpper(w)) {		/* Large capital */
; 					b |= 2;
; 				} else {
; 					if (IsLower(w)) {	/* Small capital */
; 						b |= 1; w -= 0x20;
; 					}
; 				}
; 			}
; 		}
; 		dj->fn[i++] = (BYTE)w;
; 	}
; 
; 	if (dj->fn[0] == 0xE5) dj->fn[0] = 0x05;	/* If the first char collides with 0xE5, replace it with 0x05 */
; 
; 	if (ni == 8) b <<= 2;
; 	if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03)	/* Create LFN entry when there are composite capitals */
; 		cf |= NS_LFN;
; 	if (!(cf & NS_LFN)) {						/* When LFN is in 8.3 format without extended char, NT flags are created */
; 		if ((b & 0x03) == 0x01) cf |= NS_EXT;	/* NT flag (Extension has only small capital) */
; 		if ((b & 0x0C) == 0x04) cf |= NS_BODY;	/* NT flag (Filename has only small capital) */
; 	}
; 
; 	dj->fn[11] = cf;	/* SFN is created */
; 
; 
; #else	/* Non-LFN configuration */
; 	BYTE b, c, d, *sfn;
; 	int ni, si, i;
; 	const char *p;
; 
; 	/* Create file name in directory form */
; 	sfn = dj->fn;
	movw R30,R20
	ldd R2,z+20
	ldd R3,z+21
	std y+5,R3
	std y+4,R2
	.dbline 1211
; 	mem_set(sfn, ' ', 11);
	ldi R24,11
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldi R18,32
	ldi R19,0
	movw R16,R2
	xcall _mem_set
	.dbline 1212
; 	si = i = b = 0; ni = 8;
	clr R0
	std y+6,R0
	clr R2
	clr R3
	std y+3,R3
	std y+2,R2
	std y+8,R3
	std y+7,R2
	.dbline 1212
	ldi R24,8
	ldi R25,0
	movw R12,R24
	.dbline 1213
; 	p = *path;
	ldd R30,y+19
	ldd R31,y+20
	ldd R22,z+0
	ldd R23,z+1
	.dbline 1227
; #if _FS_RPATH
; 	if (p[si] == '.') { /* Is this a dot entry? */
; 		for (;;) {
; 			c = p[si++];
; 			if (c != '.' || si >= 3) break;
; 			sfn[i++] = c;
; 		}
; 		if (c != '/' && c != '\\' && c >= ' ') return FR_INVALID_NAME;
; 		*path = &p[si];									/* Rerurn pointer to the next segment */
; 		sfn[11] = (c < ' ') ? NS_LAST|NS_DOT : NS_DOT;	/* Set last segment flag if end of path */
; 		return FR_OK;
; 	}
; #endif
; 	for (;;) {
L241:
	.dbline 1227
	.dbline 1228
; 		c = p[si++];
	ldd R2,y+7
	ldd R3,y+8
	movw R24,R2
	adiw R24,1
	std y+8,R25
	std y+7,R24
	movw R30,R2
	add R30,R22
	adc R31,R23
	lpm R20,Z
	.dbline 1229
; 		if (c < ' ' || c == '/' || c == '\\') break;	/* Break on end of segment */
	cpi R20,32
	brlo L248
X135:
	cpi R20,47
	breq L248
X136:
	cpi R20,92
	brne L245
X137:
L248:
	.dbline 1229
	xjmp L243
L245:
	.dbline 1230
; 		if (c == '.' || i >= ni) {
	cpi R20,46
	breq L251
X138:
	ldd R0,y+2
	ldd R1,y+3
	cp R0,R12
	cpc R1,R13
	brlt L249
X139:
L251:
	.dbline 1230
	.dbline 1231
; 			if (ni != 8 || c != '.') return FR_INVALID_NAME;
	movw R24,R12
	cpi R24,8
	ldi R30,0
	cpc R25,R30
	brne L254
X140:
	cpi R20,46
	breq L252
X141:
L254:
	.dbline 1231
	ldi R16,6
	xjmp L240
L252:
	.dbline 1232
; 			i = 8; ni = 11;
	ldi R24,8
	ldi R25,0
	std y+3,R25
	std y+2,R24
	.dbline 1232
	ldi R24,11
	movw R12,R24
	.dbline 1233
; 			b <<= 2; continue;
	ldd R0,y+6
	lsl R0
	lsl R0
	std y+6,R0
	.dbline 1233
	xjmp L241
L249:
	.dbline 1235
; 		}
; 		if (c >= 0x80) {				/* Extended char */
	cpi R20,128
	brlo L255
X142:
	.dbline 1235
	.dbline 1239
; #ifdef _EXCVT
; 			c = cvt[c - 0x80];			/* Convert extend char (SBCS) */
; #else
; 			b |= 3;						/* Eliminate NT flag if ext char is exist */
	ldd R24,y+6
	ori R24,3
	std y+6,R24
	.dbline 1244
; #if !_DF1S	/* ASCII only cfg */
; 			return FR_INVALID_NAME;
; #endif
; #endif
; 		}
L255:
	.dbline 1245
; 		if (IsDBCS1(c)) {				/* If it is DBC 1st byte */
	cpi R20,129
	brsh X163
	xjmp L257
X163:
X143:
	ldi R24,254
	cp R24,R20
	brsh X164
	xjmp L257
X164:
X144:
	.dbline 1245
	.dbline 1246
; 			d = p[si++];				/* Get 2nd byte */
	ldd R10,y+7
	ldd R11,y+8
	movw R24,R10
	adiw R24,1
	std y+8,R25
	std y+7,R24
	movw R30,R10
	add R30,R22
	adc R31,R23
	lpm R14,Z
	.dbline 1247
; 			if (!IsDBCS2(d) || i >= ni - 1)	/* Reject invalid DBC */
	mov R24,R14
	cpi R24,65
	brlo L263
X145:
	ldi R24,90
	cp R24,R14
	brsh L264
X146:
L263:
	mov R24,R14
	cpi R24,97
	brlo L265
X147:
	ldi R24,122
	cp R24,R14
	brsh L264
X148:
L265:
	mov R24,R14
	cpi R24,129
	brlo L261
X149:
	ldi R24,254
	cp R24,R14
	brlo L261
X150:
L264:
	movw R24,R12
	sbiw R24,1
	ldd R0,y+2
	ldd R1,y+3
	cp R0,R24
	cpc R1,R25
	brlt L259
X151:
L261:
	.dbline 1248
; 				return FR_INVALID_NAME;
	ldi R16,6
	xjmp L240
L259:
	.dbline 1249
; 			sfn[i++] = c;
	ldd R10,y+2
	ldd R11,y+3
	movw R24,R10
	adiw R24,1
	std y+3,R25
	std y+2,R24
	movw R30,R10
	ldd R0,y+4
	ldd R1,y+5
	add R30,R0
	adc R31,R1
	std z+0,R20
	.dbline 1250
; 			sfn[i++] = d;
	movw R10,R24
	adiw R24,1
	std y+3,R25
	std y+2,R24
	movw R30,R10
	ldd R0,y+4
	ldd R1,y+5
	add R30,R0
	adc R31,R1
	std z+0,R14
	.dbline 1251
; 		} else {
	xjmp L241
L257:
	.dbline 1251
	.dbline 1252
; 			if (chk_chr(" \"*+,[=]|\x7F", c))	/* Reject unallowable chrs for SFN */
	mov R18,R20
	clr R19
	ldi R16,<L268
	ldi R17,>L268
	xcall _chk_chr
	movw R14,R16
	cpi R16,0
	cpc R16,R17
	breq L266
X152:
	.dbline 1253
; 				return FR_INVALID_NAME;
	ldi R16,6
	xjmp L240
L266:
	.dbline 1254
; 			if (IsUpper(c)) {
	cpi R20,65
	brlo L269
X153:
	ldi R24,90
	cp R24,R20
	brlo L269
X154:
	.dbline 1254
	.dbline 1255
; 				b |= 2;
	ldd R24,y+6
	ori R24,2
	std y+6,R24
	.dbline 1256
; 			} else {
	xjmp L270
L269:
	.dbline 1256
	.dbline 1257
; 				if (IsLower(c)) {
	cpi R20,97
	brlo L271
X155:
	ldi R24,122
	cp R24,R20
	brlo L271
X156:
	.dbline 1257
	.dbline 1258
; 					b |= 1; c -= 0x20;
	ldd R24,y+6
	ori R24,1
	std y+6,R24
	.dbline 1258
	subi R20,32
	.dbline 1259
; 				}
L271:
	.dbline 1260
; 			}
L270:
	.dbline 1261
; 			sfn[i++] = c;
	ldd R14,y+2
	ldd R15,y+3
	movw R24,R14
	adiw R24,1
	std y+3,R25
	std y+2,R24
	movw R30,R14
	ldd R0,y+4
	ldd R1,y+5
	add R30,R0
	adc R31,R1
	std z+0,R20
	.dbline 1262
; 		}
	.dbline 1263
; 	}
	.dbline 1227
	.dbline 1227
	xjmp L241
L243:
	.dbline 1264
; 	*path = &p[si];						/* Rerurn pointer to the next segment */
	ldd R2,y+7
	ldd R3,y+8
	add R2,R22
	adc R3,R23
	ldd R30,y+19
	ldd R31,y+20
	std z+1,R3
	std z+0,R2
	.dbline 1265
; 	c = (c < ' ') ? NS_LAST : 0;		/* Set last segment flag if end of path */
	cpi R20,32
	brsh L273
X157:
	ldi R22,4
	ldi R23,0
	xjmp L274
L273:
	clr R22
	clr R23
L274:
	mov R20,R22
	.dbline 1267
; 
; 	if (!i) return FR_INVALID_NAME;		/* Reject null string */
	ldd R0,y+2
	ldd R1,y+3
	tst R0
	brne L275
	tst R1
	brne L275
X158:
	.dbline 1267
	ldi R16,6
	xjmp L240
L275:
	.dbline 1268
; 	if (sfn[0] == 0xE5) sfn[0] = 0x05;	/* When first char collides with 0xE5, replace it with 0x05 */
	ldd R30,y+4
	ldd R31,y+5
	ldd R24,z+0
	cpi R24,229
	brne L277
X159:
	.dbline 1268
	ldi R24,5
	std z+0,R24
L277:
	.dbline 1270
; 
; 	if (ni == 8) b <<= 2;
	movw R24,R12
	cpi R24,8
	ldi R30,0
	cpc R25,R30
	brne L279
X160:
	.dbline 1270
	ldd R0,y+6
	lsl R0
	lsl R0
	std y+6,R0
L279:
	.dbline 1271
; 	if ((b & 0x03) == 0x01) c |= NS_EXT;	/* NT flag (Extension has only small capital) */
	ldd R24,y+6
	andi R24,3
	cpi R24,1
	brne L281
X161:
	.dbline 1271
	ori R20,16
L281:
	.dbline 1272
; 	if ((b & 0x0C) == 0x04) c |= NS_BODY;	/* NT flag (Filename has only small capital) */
	ldd R24,y+6
	andi R24,12
	cpi R24,4
	brne L283
X162:
	.dbline 1272
	ori R20,8
L283:
	.dbline 1274
; 
; 	sfn[11] = c;		/* Store NT flag, File name is created */
	ldd R30,y+4
	ldd R31,y+5
	std z+11,R20
	.dbline 1277
; #endif
; 
; 	return FR_OK;
	clr R16
	.dbline -2
L240:
	.dbline 0 ; func end
	adiw R28,9
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym r p 22 pkc
	.dbsym l si 7 I
	.dbsym l b 6 c
	.dbsym l sfn 4 pc
	.dbsym r ni 12 I
	.dbsym l i 2 I
	.dbsym r d 14 c
	.dbsym r c 20 c
	.dbsym l path 19 ppkc
	.dbsym r dj 20 pS[_DIR_]
	.dbend
	.dbfunc s get_fileinfo _get_fileinfo fV
	.dbstruct 0 22 _FILINFO_
	.dbfield 0 fsize l
	.dbfield 4 fdate s
	.dbfield 6 ftime s
	.dbfield 8 fattrib c
	.dbfield 9 fname A[13:13]c
	.dbend
;             nt -> R10
;              p -> y+2
;            dir -> y+0
;              i -> R12,R13
;              c -> R14
;            fno -> y+14
;             dj -> R10,R11
	.even
_get_fileinfo:
	st -y,r19
	st -y,r18
	xcall push_xgsetF0FC
	movw R10,R16
	sbiw R28,4
	.dbline -1
	.dbline 1292
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Get file information from directory entry                             */
; /*-----------------------------------------------------------------------*/
; #if _FS_MINIMIZE <= 1
; static
; void get_fileinfo (		/* No return code */
; 	DIR *dj,			/* Pointer to the directory object */
; 	FILINFO *fno	 	/* Pointer to store the file information */
; )
; {
	.dbline 1301
; 	int i;
; 	BYTE c, nt, *dir;
; 	char *p;
; #if _USE_LFN
; 	XCHAR *tp;
; #endif
; 
; 
; 	p = fno->fname;
	ldd R24,y+14
	ldd R25,y+15
	adiw R24,9
	std y+3,R25
	std y+2,R24
	.dbline 1302
; 	if (dj->sect) {
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R10
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne X178
	xjmp L286
X178:
X165:
	.dbline 1302
	.dbline 1303
; 		dir = dj->dir;
	ldd R2,z+18
	ldd R3,z+19
	std y+1,R3
	std y+0,R2
	.dbline 1304
; 		nt = dir[DIR_NTres];		/* NT flag */
	movw R30,R2
	ldd R10,z+12
	.dbline 1305
; 		for (i = 0; i < 8; i++) {	/* Copy name body */
	clr R12
	clr R13
L288:
	.dbline 1305
	.dbline 1306
; 			c = dir[i];
	movw R30,R12
	ldd R0,y+0
	ldd R1,y+1
	add R30,R0
	adc R31,R1
	ldd R14,z+0
	.dbline 1307
; 			if (c == ' ') break;
	mov R24,R14
	cpi R24,32
	brne L292
X166:
	.dbline 1307
	xjmp L290
L292:
	.dbline 1308
; 			if (c == 0x05) c = 0xE5;
	mov R24,R14
	cpi R24,5
	brne L294
X167:
	.dbline 1308
	ldi R24,229
	mov R14,R24
L294:
	.dbline 1309
; 			if ((nt & 0x08) && IsUpper(c)) c += 0x20;
	sbrs R10,3
	rjmp L296
X168:
	mov R24,R14
	cpi R24,65
	brlo L296
X169:
	ldi R24,90
	cp R24,R14
	brlo L296
X170:
	.dbline 1309
	mov R24,R14
	subi R24,224    ; addi 32
	mov R14,R24
L296:
	.dbline 1310
; 			*p++ = c;
	ldd R30,y+2
	ldd R31,y+3
	st Z+,R14
	std y+3,R31
	std y+2,R30
	.dbline 1311
; 		}
L289:
	.dbline 1305
	movw R24,R12
	adiw R24,1
	movw R12,R24
	.dbline 1305
	cpi R24,8
	ldi R30,0
	cpc R25,R30
	brlt L288
X171:
L290:
	.dbline 1312
; 		if (dir[8] != ' ') {		/* Copy name extension */
	ldd R30,y+0
	ldd R31,y+1
	ldd R24,z+8
	cpi R24,32
	breq L298
X172:
	.dbline 1312
	.dbline 1313
; 			*p++ = '.';
	ldi R24,46
	ldd R30,y+2
	ldd R31,y+3
	st Z+,R24
	std y+3,R31
	std y+2,R30
	.dbline 1314
; 			for (i = 8; i < 11; i++) {
	ldi R24,8
	ldi R25,0
	movw R12,R24
L300:
	.dbline 1314
	.dbline 1315
; 				c = dir[i];
	movw R30,R12
	ldd R0,y+0
	ldd R1,y+1
	add R30,R0
	adc R31,R1
	ldd R14,z+0
	.dbline 1316
; 				if (c == ' ') break;
	mov R24,R14
	cpi R24,32
	brne L304
X173:
	.dbline 1316
	xjmp L302
L304:
	.dbline 1317
; 				if ((nt & 0x10) && IsUpper(c)) c += 0x20;
	sbrs R10,4
	rjmp L306
X174:
	mov R24,R14
	cpi R24,65
	brlo L306
X175:
	ldi R24,90
	cp R24,R14
	brlo L306
X176:
	.dbline 1317
	mov R24,R14
	subi R24,224    ; addi 32
	mov R14,R24
L306:
	.dbline 1318
; 				*p++ = c;
	ldd R30,y+2
	ldd R31,y+3
	st Z+,R14
	std y+3,R31
	std y+2,R30
	.dbline 1319
; 			}
L301:
	.dbline 1314
	movw R24,R12
	adiw R24,1
	movw R12,R24
	.dbline 1314
	cpi R24,11
	ldi R30,0
	cpc R25,R30
	brlt L300
X177:
L302:
	.dbline 1320
; 		}
L298:
	.dbline 1321
; 		fno->fattrib = dir[DIR_Attr];				/* Attribute */
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+11
	ldd R30,y+14
	ldd R31,y+15
	std z+8,R2
	.dbline 1322
; 		fno->fsize = LD_DWORD(dir+DIR_FileSize);	/* Size */
	ldi R24,24
	ldi R25,0
	ldd R30,y+0
	ldd R31,y+1
	ldd R16,z+31
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	ldd R30,y+0
	ldd R31,y+1
	ldd R6,z+30
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+29
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+28
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R30,y+14
	ldd R31,y+15
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 1323
; 		fno->fdate = LD_WORD(dir+DIR_WrtDate);		/* Date */
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+24
	clr R3
	ldd R4,z+25
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	ldd R30,y+14
	ldd R31,y+15
	std z+5,R5
	std z+4,R4
	.dbline 1324
; 		fno->ftime = LD_WORD(dir+DIR_WrtTime);		/* Time */
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+22
	clr R3
	ldd R4,z+23
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	ldd R30,y+14
	ldd R31,y+15
	std z+7,R5
	std z+6,R4
	.dbline 1325
; 	}
L286:
	.dbline 1326
; 	*p = 0;
	clr R2
	ldd R30,y+2
	ldd R31,y+3
	std z+0,R2
	.dbline -2
L285:
	.dbline 0 ; func end
	adiw R28,4
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym r nt 10 c
	.dbsym l p 2 pc
	.dbsym l dir 0 pc
	.dbsym r i 12 I
	.dbsym r c 14 c
	.dbsym l fno 14 pS[_FILINFO_]
	.dbsym r dj 10 pS[_DIR_]
	.dbend
	.dbfunc s follow_path _follow_path fc
;           last -> R14
;            res -> R10
;            dir -> R14,R15
;           path -> y+10
;             dj -> R12,R13
	.even
_follow_path:
	st -y,r19
	st -y,r18
	xcall push_xgsetF0FC
	movw R12,R16
	.dbline -1
	.dbline 1365
; 
; #if _USE_LFN
; 	tp = fno->lfname;
; 	if (tp) {
; 		WCHAR w, *lfn;
; 
; 		i = 0;
; 		if (dj->sect && dj->lfn_idx != 0xFFFF) {/* Get LFN if available */
; 			lfn = dj->lfn;
; 			while ((w = *lfn++) != 0) {			/* Get an LFN char */
; #if !_LFN_UNICODE
; 				w = ff_convert(w, 0);			/* Unicode -> OEM conversion */
; 				if (!w) { i = 0; break; }		/* Could not convert, no LFN */
; 				if (_DF1S && w >= 0x100)		/* Put 1st byte if it is a DBC */
; 					tp[i++] = (XCHAR)(w >> 8);
; 				if (i >= fno->lfsize - 1) { i = 0; break; }	/* Buffer overrun, no LFN */
; #endif
; 				tp[i++] = (XCHAR)w;
; 			}
; 		}
; 		tp[i] = 0;	/* Terminator */
; 	}
; #endif
; }
; #endif /* _FS_MINIMIZE <= 1 */
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Follow a file path                                                    */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT follow_path (	/* FR_OK(0): successful, !=0: error code */
; 	DIR *dj,			/* Directory object to return last directory and found object */
; 	const XCHAR *path	/* Full-path string to find a file or directory */
; )
; {
	.dbline 1377
; 	FRESULT res;
; 	BYTE *dir, last;
; 
; 
; #if _FS_RPATH
; 	if (*path == '/' || *path == '\\') { /* There is a heading separator */
; 		path++;	dj->sclust = 0;		/* Strip it and start from the root dir */
; 	} else {							/* No heading saparator */
; 		dj->sclust = dj->fs->cdir;	/* Start from the current dir */
; 	}
; #else
; 	if (*path == '/' || *path == '\\')	/* Strip heading separator if exist */
	ldd R30,y+10
	ldd R31,y+11
	lpm R2,Z
	clr R3
	mov R24,R2
	cpi R24,47
	breq L311
X179:
	cpi R24,92
	brne L309
X180:
L311:
	.dbline 1378
; 		path++;
	ldd R24,y+10
	ldd R25,y+11
	adiw R24,1
	std y+11,R25
	std y+10,R24
L309:
	.dbline 1379
; 	dj->sclust = 0;						/* Start from the root dir */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R12
	std z+6,R20
	std z+7,R21
	std z+8,R22
	std z+9,R23
	.dbline 1382
; #endif
; 
; 	if ((UINT)*path < ' ') {			/* Null path means the start directory itself */
	ldd R30,y+10
	ldd R31,y+11
	lpm R24,Z
	clr R25
	cpi R24,32
	ldi R30,0
	cpc R25,R30
	brsh L312
X181:
	.dbline 1382
	.dbline 1383
; 		res = dir_seek(dj, 0);
	clr R18
	clr R19
	movw R16,R12
	xcall _dir_seek
	mov R10,R16
	.dbline 1384
; 		dj->dir = NULL;
	clr R2
	clr R3
	movw R30,R12
	std z+19,R3
	std z+18,R2
	.dbline 1386
; 
; 	} else {							/* Follow path */
	xjmp L313
L312:
	.dbline 1386
	.dbline 1387
; 		for (;;) {
L314:
	.dbline 1387
	.dbline 1388
; 			res = create_name(dj, &path);	/* Get a segment */
	movw R18,R28
	subi R18,246  ; offset = 10
	sbci R19,255
	movw R16,R12
	xcall _create_name
	mov R14,R16
	mov R10,R14
	.dbline 1389
; 			if (res != FR_OK) break;
	tst R16
	breq L318
X182:
	.dbline 1389
	xjmp L316
L318:
	.dbline 1390
; 			res = dir_find(dj);				/* Find it */
	movw R16,R12
	xcall _dir_find
	mov R14,R16
	mov R10,R14
	.dbline 1391
; 			last = *(dj->fn+11) & NS_LAST;
	movw R30,R12
	push R26
	push R27
	ldd R26,z+20
	ldd R27,z+21
	movw R30,R26
	pop R27
	pop R26
	ldd R24,z+11
	andi R24,4
	mov R14,R24
	.dbline 1392
; 			if (res != FR_OK) {				/* Could not find the object */
	tst R16
	breq L320
X183:
	.dbline 1392
	.dbline 1393
; 				if (res == FR_NO_FILE && !last)
	cpi R16,4
	breq X188
	xjmp L316
X188:
X184:
	tst R14
	breq X189
	xjmp L316
X189:
X185:
	.dbline 1394
; 					res = FR_NO_PATH;
	ldi R24,5
	mov R10,R24
	.dbline 1395
; 				break;
	xjmp L316
L320:
	.dbline 1397
; 			}
; 			if (last) break;				/* Last segment match. Function completed. */
	tst R14
	breq L324
X186:
	.dbline 1397
	xjmp L316
L324:
	.dbline 1398
; 			dir = dj->dir;					/* There is next segment. Follow the sub directory */
	movw R30,R12
	ldd R14,z+18
	ldd R15,z+19
	.dbline 1399
; 			if (!(dir[DIR_Attr] & AM_DIR)) { /* Cannot follow because it is a file */
	movw R30,R14
	ldd R2,z+11
	sbrc R2,4
	rjmp L326
X187:
	.dbline 1399
	.dbline 1400
; 				res = FR_NO_PATH; break;
	ldi R24,5
	mov R10,R24
	.dbline 1400
	xjmp L316
L326:
	.dbline 1402
; 			}
; 			dj->sclust = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO);
	movw R30,R14
	ldd R2,z+26
	clr R3
	ldd R4,z+27
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,z+20
	clr R7
	ldd R8,z+21
	clr R9
	mov R9,R8
	clr R8
	or R8,R6
	or R9,R7
	movw R6,R8
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R6,R2
	or R7,R3
	or R8,R4
	or R9,R5
	movw R30,R12
	std z+6,R6
	std z+7,R7
	std z+8,R8
	std z+9,R9
	.dbline 1403
; 		}
	.dbline 1387
	.dbline 1387
	xjmp L314
L316:
	.dbline 1404
; 	}
L313:
	.dbline 1406
; 
; 	return res;
	mov R16,R10
	.dbline -2
L308:
	.dbline 0 ; func end
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym r last 14 c
	.dbsym r res 10 c
	.dbsym r dir 14 pc
	.dbsym l path 10 pkc
	.dbsym r dj 12 pS[_DIR_]
	.dbend
	.area lit(rom, con, rel)
L329:
	.byte 'F,'A,'T,0
	.area text(rom, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\ff.c
	.dbfunc s check_fs _check_fs fc
	.dbsym s fatstr L329 A[4:4]kc
;           sect -> y+9
;             fs -> R20,R21
	.even
_check_fs:
	st -y,r19
	st -y,r18
	xcall push_xgset300C
	movw R20,R16
	sbiw R28,5
	.dbline -1
	.dbline 1421
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Load boot record and check if it is an FAT boot record                */
; /*-----------------------------------------------------------------------*/
; 
; static
; BYTE check_fs (	/* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record, 3:Error */
; 	FATFS *fs,	/* File system object */
; 	DWORD sect	/* Sector# (lba) to check if it is an FAT boot record or not */
; )
; {
	.dbline 1425
; 	static const char fatstr[] = "FAT";
; 
; 
; 	if (disk_read(fs->drive, fs->win, sect, 1) != RES_OK)	/* Load boot record */
	ldi R24,1
	std y+4,R24
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R20
	subi R18,210  ; offset = 46
	sbci R19,255
	movw R30,R20
	ldd R16,z+1
	xcall _disk_read
	tst R16
	breq L330
X190:
	.dbline 1426
; 		return 3;
	ldi R16,3
	xjmp L328
L330:
	.dbline 1427
; 	if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55)		/* Check record signature (always placed at offset 510 even if the sector size is >512) */
	movw R30,R20
	subi R30,212  ; addi 556
	sbci R31,253
	ldd R2,z+0
	subi R30,44
	sbci R31,2
	clr R3
	subi R30,211  ; addi 557
	sbci R31,253
	ldd R24,z+0
	clr R25
	mov R25,R24
	clr R24
	or R24,R2
	or R25,R3
	cpi R24,85
	ldi R30,170
	cpc R25,R30
	breq L332
X191:
	.dbline 1428
; 		return 2;
	ldi R16,2
	xjmp L328
L332:
	.dbline 1430
; 
; 	if (!mem_cmp(&fs->win[BS_FilSysType], fatstr, 3))	/* Check FAT signature */
	ldi R24,3
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldi R18,<L329
	ldi R19,>L329
	movw R16,R20
	subi R16,156  ; offset = 100
	sbci R17,255
	xcall _mem_cmp
	cpi R16,0
	cpc R16,R17
	brne L334
X192:
	.dbline 1431
; 		return 0;
	clr R16
	xjmp L328
L334:
	.dbline 1432
; 	if (!mem_cmp(&fs->win[BS_FilSysType32], fatstr, 3) && !(fs->win[BPB_ExtFlags] & 0x80))
	ldi R24,3
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldi R18,<L329
	ldi R19,>L329
	movw R16,R20
	subi R16,128  ; offset = 128
	sbci R17,255
	xcall _mem_cmp
	movw R10,R16
	cpi R16,0
	cpc R16,R17
	brne L336
X193:
	movw R30,R20
	subi R30,170  ; addi 86
	sbci R31,255
	ldd R2,z+0
	sbrc R2,7
	rjmp L336
X194:
	.dbline 1433
; 		return 0;
	clr R16
	xjmp L328
L336:
	.dbline 1435
; 
; 	return 1;
	ldi R16,1
	.dbline -2
L328:
	.dbline 0 ; func end
	adiw R28,5
	xcall pop_xgset300C
	adiw R28,2
	ret
	.dbsym l sect 9 l
	.dbsym r fs 20 pS[_FATFS_]
	.dbend
	.dbfunc s auto_mount _auto_mount fc
;            tbl -> R14,R15
;            res -> R10
;          mclst -> y+17
;          bsect -> y+13
;          tsect -> y+9
;              p -> R12,R13
;           stat -> R10
;            vol -> R14,R15
;          fsize -> y+5
;            fmt -> R10
;             fs -> R12,R13
;         chk_wp -> y+37
;            rfs -> y+35
;           path -> R10,R11
	.even
_auto_mount:
	st -y,r19
	st -y,r18
	xcall push_xgsetF0FC
	movw R10,R16
	sbiw R28,25
	.dbline -1
	.dbline 1451
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Make sure that the file system is valid                               */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT auto_mount (	/* FR_OK(0): successful, !=0: any error occured */
; 	const XCHAR **path,	/* Pointer to pointer to the path name (drive number) */
; 	FATFS **rfs,		/* Pointer to pointer to the found file system object */
; 	BYTE chk_wp			/* !=0: Check media write protection for write access */
; )
; {
	.dbline 1457
; 	FRESULT res;
; 	BYTE fmt, *tbl;
; 	UINT vol;
; 	DSTATUS stat;
; 	DWORD bsect, fsize, tsect, mclst;
; 	const XCHAR *p = *path;
	movw R30,R10
	ldd R12,z+0
	ldd R13,z+1
	.dbline 1462
; 	FATFS *fs;
; 
; 
; 	/* Get logical drive number from the path name */
; 	vol = p[0] - '0';				/* Is there a drive number? */
	movw R30,R12
	lpm R24,Z
	clr R25
	sbiw R24,48
	movw R14,R24
	.dbline 1463
; 	if (vol <= 9 && p[1] == ':') {	/* Found a drive number, get and strip it */
	ldi R24,9
	ldi R25,0
	cp R24,R14
	cpc R25,R15
	brlo L339
X195:
	adiw R30,1
	lpm R24,Z
	cpi R24,58
	brne L339
X196:
	.dbline 1463
	.dbline 1464
; 		p += 2; *path = p;			/* Return pointer to the path name */
	movw R24,R12
	adiw R24,2
	movw R12,R24
	.dbline 1464
	movw R30,R10
	std z+1,R13
	std z+0,R12
	.dbline 1465
; 	} else {						/* No drive number is given */
	xjmp L340
L339:
	.dbline 1465
	.dbline 1469
; #if _FS_RPATH
; 		vol = Drive;				/* Use current drive */
; #else
; 		vol = 0;					/* Use drive 0 */
	clr R14
	clr R15
	.dbline 1471
; #endif
; 	}
L340:
	.dbline 1474
; 
; 	/* Check if the logical drive is valid or not */
; 	if (vol >= _DRIVES) 			/* Is the drive number valid? */
	movw R24,R14
	cpi R24,1
	ldi R30,0
	cpc R25,R30
	brlo L341
X197:
	.dbline 1475
; 		return FR_INVALID_DRIVE;
	ldi R16,11
	xjmp L338
L341:
	.dbline 1476
; 	*rfs = fs = FatFs[vol];			/* Returen pointer to the corresponding file system object */
	ldi R16,2
	ldi R17,0
	movw R18,R14
	xcall empy16s
	movw R30,R16
	ldi R24,<_FatFs
	ldi R25,>_FatFs
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	movw R12,R2
	ldd R30,y+35
	ldd R31,y+36
	std z+1,R3
	std z+0,R2
	.dbline 1477
; 	if (!fs) return FR_NOT_ENABLED;	/* Is the file system object registered? */
	tst R2
	brne L343
	tst R3
	brne L343
X198:
	.dbline 1477
	ldi R16,12
	xjmp L338
L343:
	.dbline 1479
; 
; 	ENTER_FF(fs);					/* Lock file system */
	.dbline 1481
; 
; 	if (fs->fs_type) {				/* If the logical drive has been mounted */
	movw R30,R12
	ldd R2,z+0
	tst R2
	breq L345
X199:
	.dbline 1481
	.dbline 1482
; 		stat = disk_status(fs->drive);
	ldd R16,z+1
	xcall _disk_status
	mov R10,R16
	.dbline 1483
; 		if (!(stat & STA_NOINIT)) {	/* and the physical drive is kept initialized (has not been changed), */
	sbrc R16,0
	rjmp L347
X200:
	.dbline 1483
	.dbline 1485
; #if !_FS_READONLY
; 			if (chk_wp && (stat & STA_PROTECT))	/* Check write protection if needed */
	ldd R0,y+37
	tst R0
	breq L349
X201:
	sbrs R16,2
	rjmp L349
X202:
	.dbline 1486
; 				return FR_WRITE_PROTECTED;
	ldi R16,10
	xjmp L338
L349:
	.dbline 1488
; #endif
; 			return FR_OK;			/* The file system object is valid */
	clr R16
	xjmp L338
L347:
	.dbline 1490
; 		}
; 	}
L345:
	.dbline 1494
; 
; 	/* The logical drive must be mounted. Following code attempts to mount the volume */
; 
; 	fs->fs_type = 0;					/* Clear the file system object */
	clr R2
	movw R30,R12
	std z+0,R2
	.dbline 1495
; 	fs->drive = (BYTE)LD2PD(vol);		/* Bind the logical drive and a physical drive */
	std z+1,R14
	.dbline 1496
; 	stat = disk_initialize(fs->drive);	/* Initialize low level disk I/O layer */
	ldd R16,z+1
	xcall _disk_initialize
	mov R14,R16
	mov R10,R14
	.dbline 1497
; 	if (stat & STA_NOINIT)				/* Check if the drive is ready */
	sbrs R16,0
	rjmp L351
X203:
	.dbline 1498
; 		return FR_NOT_READY;
	ldi R16,3
	xjmp L338
L351:
	.dbline 1504
; #if _MAX_SS != 512						/* Get disk sector size if needed */
; 	if (disk_ioctl(fs->drive, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS)
; 		return FR_NO_FILESYSTEM;
; #endif
; #if !_FS_READONLY
; 	if (chk_wp && (stat & STA_PROTECT))	/* Check disk write protection if needed */
	ldd R0,y+37
	tst R0
	breq L353
X204:
	sbrs R10,2
	rjmp L353
X205:
	.dbline 1505
; 		return FR_WRITE_PROTECTED;
	ldi R16,10
	xjmp L338
L353:
	.dbline 1508
; #endif
; 	/* Search FAT partition on the drive */
; 	fmt = check_fs(fs, bsect = 0);		/* Check sector 0 as an SFD format */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+13,R20
	std y+14,R21
	std y+15,R22
	std y+16,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	movw R16,R12
	xcall _check_fs
	mov R10,R16
	.dbline 1509
; 	if (fmt == 1) {						/* Not an FAT boot record, it may be patitioned */
	cpi R16,1
	breq X221
	xjmp L355
X221:
X206:
	.dbline 1509
	.dbline 1511
; 		/* Check a partition listed in top of the partition table */
; 		tbl = &fs->win[MBR_Table + LD2PT(vol) * 16];	/* Partition table */
	movw R24,R12
	subi R24,20  ; offset = 492
	sbci R25,254
	movw R14,R24
	.dbline 1512
; 		if (tbl[4]) {									/* Is the partition existing? */
	movw R30,R24
	ldd R2,z+4
	tst R2
	brne X222
	xjmp L357
X222:
X207:
	.dbline 1512
	.dbline 1513
; 			bsect = LD_DWORD(&tbl[8]);					/* Partition offset in LBA */
	ldi R24,24
	ldi R25,0
	ldd R16,z+11
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R14
	ldd R6,z+10
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+9
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+8
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	std y+13,R2
	std y+14,R3
	std y+15,R4
	std y+16,R5
	.dbline 1514
; 			fmt = check_fs(fs, bsect);					/* Check the partition */
	ldd R2,y+13
	ldd R3,y+14
	ldd R4,y+15
	ldd R5,y+16
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R16,R12
	xcall _check_fs
	mov R14,R16
	mov R10,R14
	.dbline 1515
; 		}
L357:
	.dbline 1516
; 	}
L355:
	.dbline 1517
; 	if (fmt == 3) return FR_DISK_ERR;
	mov R24,R10
	cpi R24,3
	brne L359
X208:
	.dbline 1517
	ldi R16,1
	xjmp L338
L359:
	.dbline 1518
; 	if (fmt || LD_WORD(fs->win+BPB_BytsPerSec) != SS(fs))	/* No valid FAT patition is found */
	tst R10
	brne L363
X209:
	movw R30,R12
	ldd R2,z+57
	clr R3
	ldd R24,z+58
	clr R25
	mov R25,R24
	clr R24
	or R24,R2
	or R25,R3
	cpi R24,0
	ldi R30,2
	cpc R25,R30
	breq L361
X210:
L363:
	.dbline 1519
; 		return FR_NO_FILESYSTEM;
	ldi R16,13
	xjmp L338
L361:
	.dbline 1522
; 
; 	/* Initialize the file system object */
; 	fsize = LD_WORD(fs->win+BPB_FATSz16);				/* Number of sectors per FAT */
	movw R30,R12
	subi R30,188  ; addi 68
	sbci R31,255
	ldd R2,z+0
	subi R30,68
	sbci R31,0
	clr R3
	subi R30,187  ; addi 69
	sbci R31,255
	ldd R4,z+0
	subi R30,69
	sbci R31,0
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	std y+5,R2
	std y+6,R3
	std y+7,R4
	std y+8,R5
	.dbline 1523
; 	if (!fsize) fsize = LD_DWORD(fs->win+BPB_FATSz32);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X223
	xjmp L364
X223:
X211:
	.dbline 1523
	ldi R24,24
	ldi R25,0
	subi R30,171  ; addi 85
	sbci R31,255
	ldd R16,z+0
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	subi R30,172  ; addi 84
	sbci R31,255
	ldd R6,z+0
	subi R30,84
	sbci R31,0
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,173  ; addi 83
	sbci R31,255
	ldd R6,z+0
	subi R30,83
	sbci R31,0
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,174  ; addi 82
	sbci R31,255
	ldd R6,z+0
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	std y+5,R2
	std y+6,R3
	std y+7,R4
	std y+8,R5
L364:
	.dbline 1524
; 	fs->sects_fat = fsize;
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R12
	std z+22,R2
	std z+23,R3
	std z+24,R4
	std z+25,R5
	.dbline 1525
; 	fs->n_fats = fs->win[BPB_NumFATs];					/* Number of FAT copies */
	ldd R2,z+62
	std z+3,R2
	.dbline 1526
; 	fsize *= fs->n_fats;								/* (Number of sectors in FAT area) */
	clr R3
	clr R4
	clr R5
	ldd R16,y+5
	ldd R17,y+6
	ldd R18,y+7
	ldd R19,y+8
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32u
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
	.dbline 1527
; 	fs->fatbase = bsect + LD_WORD(fs->win+BPB_RsvdSecCnt); /* FAT start sector (lba) */
	movw R30,R12
	ldd R2,z+60
	clr R3
	ldd R4,z+61
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,y+13
	ldd R7,y+14
	ldd R8,y+15
	ldd R9,y+16
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+30,R6
	std z+31,R7
	std z+32,R8
	std z+33,R9
	.dbline 1528
; 	fs->csize = fs->win[BPB_SecPerClus];				/* Number of sectors per cluster */
	ldd R2,z+59
	std z+2,R2
	.dbline 1529
; 	fs->n_rootdir = LD_WORD(fs->win+BPB_RootEntCnt);	/* Nmuber of root directory entries */
	ldd R2,z+63
	clr R3
	subi R30,192  ; addi 64
	sbci R31,255
	ldd R4,z+0
	subi R30,64
	sbci R31,0
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	std z+8,R5
	std z+7,R4
	.dbline 1530
; 	tsect = LD_WORD(fs->win+BPB_TotSec16);				/* Number of sectors on the file system */
	subi R30,191  ; addi 65
	sbci R31,255
	ldd R2,z+0
	subi R30,65
	sbci R31,0
	clr R3
	subi R30,190  ; addi 66
	sbci R31,255
	ldd R4,z+0
	subi R30,66
	sbci R31,0
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	std y+9,R2
	std y+10,R3
	std y+11,R4
	std y+12,R5
	.dbline 1531
; 	if (!tsect) tsect = LD_DWORD(fs->win+BPB_TotSec32);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X224
	xjmp L366
X224:
X212:
	.dbline 1531
	ldi R24,24
	ldi R25,0
	subi R30,175  ; addi 81
	sbci R31,255
	ldd R16,z+0
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	subi R30,176  ; addi 80
	sbci R31,255
	ldd R6,z+0
	subi R30,80
	sbci R31,0
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,177  ; addi 79
	sbci R31,255
	ldd R6,z+0
	subi R30,79
	sbci R31,0
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,178  ; addi 78
	sbci R31,255
	ldd R6,z+0
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	std y+9,R2
	std y+10,R3
	std y+11,R4
	std y+12,R5
L366:
	.dbline 1532
; 	fs->max_clust = mclst = (tsect						/* Last cluster# + 1 */
	movw R30,R12
	ldd R2,z+60
	clr R3
	ldd R4,z+61
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R16,y+9
	ldd R17,y+10
	ldd R18,y+11
	ldd R19,y+12
	sub R16,R2
	sbc R17,R3
	sbc R18,R4
	sbc R19,R5
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	sub R16,R2
	sbc R17,R3
	sbc R18,R4
	sbc R19,R5
	ldd R2,z+7
	ldd R3,z+8
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	clr R4
	clr R5
	sub R16,R2
	sbc R17,R3
	sbc R18,R4
	sbc R19,R5
	ldd R2,z+2
	clr R3
	clr R4
	clr R5
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall div32u
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R2,R16
	movw R4,R18
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+21,R2
	std y+22,R3
	std y+23,R4
	std y+24,R5
	ldd R2,y+21
	ldd R3,y+22
	ldd R4,y+23
	ldd R5,y+24
	std y+17,R2
	std y+18,R3
	std y+19,R4
	std y+20,R5
	ldd R2,y+21
	ldd R3,y+22
	ldd R4,y+23
	ldd R5,y+24
	movw R30,R12
	std z+26,R2
	std z+27,R3
	std z+28,R4
	std z+29,R5
	.dbline 1536
; 		- LD_WORD(fs->win+BPB_RsvdSecCnt) - fsize - fs->n_rootdir / (SS(fs)/32)
; 		) / fs->csize + 2;
; 
; 	fmt = FS_FAT12;										/* Determine the FAT sub type */
	clr R10
	inc R10
	.dbline 1537
; 	if (mclst >= 0xFF7) fmt = FS_FAT16;					/* Number of clusters >= 0xFF5 */
	ldi R20,247
	ldi R21,15
	ldi R22,0
	ldi R23,0
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L368
X213:
	.dbline 1537
	ldi R24,2
	mov R10,R24
L368:
	.dbline 1538
; 	if (mclst >= 0xFFF7) fmt = FS_FAT32;				/* Number of clusters >= 0xFFF5 */
	ldi R20,247
	ldi R21,255
	ldi R22,0
	ldi R23,0
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L370
X214:
	.dbline 1538
	ldi R24,3
	mov R10,R24
L370:
	.dbline 1540
; 
; 	if (fmt == FS_FAT32)
	mov R24,R10
	cpi R24,3
	breq X225
	xjmp L372
X225:
X215:
	.dbline 1541
; 		fs->dirbase = LD_DWORD(fs->win+BPB_RootClus);	/* Root directory start cluster */
	ldi R24,24
	ldi R25,0
	movw R30,R12
	subi R30,163  ; addi 93
	sbci R31,255
	ldd R16,z+0
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	subi R30,164  ; addi 92
	sbci R31,255
	ldd R6,z+0
	subi R30,92
	sbci R31,0
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,165  ; addi 91
	sbci R31,255
	ldd R6,z+0
	subi R30,91
	sbci R31,0
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,166  ; addi 90
	sbci R31,255
	ldd R6,z+0
	subi R30,90
	sbci R31,0
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	std z+34,R2
	std z+35,R3
	std z+36,R4
	std z+37,R5
	xjmp L373
L372:
	.dbline 1543
; 	else
; 		fs->dirbase = fs->fatbase + fsize;				/* Root directory start sector (lba) */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R12
	ldd R6,z+30
	ldd R7,z+31
	ldd R8,z+32
	ldd R9,z+33
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+34,R6
	std z+35,R7
	std z+36,R8
	std z+37,R9
L373:
	.dbline 1544
; 	fs->database = fs->fatbase + fsize + fs->n_rootdir / (SS(fs)/32);	/* Data start sector (lba) */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R12
	ldd R6,z+30
	ldd R7,z+31
	ldd R8,z+32
	ldd R9,z+33
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	ldd R2,z+7
	ldd R3,z+8
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	clr R4
	clr R5
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+38,R6
	std z+39,R7
	std z+40,R8
	std z+41,R9
	.dbline 1548
; 
; #if !_FS_READONLY
; 	/* Initialize allocation information */
; 	fs->free_clust = 0xFFFFFFFF;
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	std z+14,R20
	std z+15,R21
	std z+16,R22
	std z+17,R23
	.dbline 1549
; 	fs->wflag = 0;
	clr R2
	std z+4,R2
	.dbline 1551
; 	/* Get fsinfo if needed */
; 	if (fmt == FS_FAT32) {
	mov R24,R10
	cpi R24,3
	breq X226
	xjmp L374
X226:
X216:
	.dbline 1551
	.dbline 1552
; 	 	fs->fsi_flag = 0;
	std z+9,R2
	.dbline 1553
; 		fs->fsi_sector = bsect + LD_WORD(fs->win+BPB_FSInfo);
	subi R30,162  ; addi 94
	sbci R31,255
	ldd R2,z+0
	subi R30,94
	sbci R31,0
	clr R3
	subi R30,161  ; addi 95
	sbci R31,255
	ldd R4,z+0
	subi R30,95
	sbci R31,0
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,y+13
	ldd R7,y+14
	ldd R8,y+15
	ldd R9,y+16
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+18,R6
	std z+19,R7
	std z+20,R8
	std z+21,R9
	.dbline 1554
; 		if (disk_read(fs->drive, fs->win, fs->fsi_sector, 1) == RES_OK &&
	ldi R24,1
	std y+4,R24
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,210  ; offset = 46
	sbci R19,255
	ldd R16,z+1
	xcall _disk_read
	mov R14,R16
	tst R16
	breq X227
	xjmp L376
X227:
X217:
	movw R30,R12
	subi R30,212  ; addi 556
	sbci R31,253
	ldd R2,z+0
	subi R30,44
	sbci R31,2
	clr R3
	subi R30,211  ; addi 557
	sbci R31,253
	ldd R24,z+0
	subi R30,45
	sbci R31,2
	clr R25
	mov R25,R24
	clr R24
	or R24,R2
	or R25,R3
	cpi R24,85
	ldi R26,170
	cpc R25,R26
	breq X228
	xjmp L376
X228:
X218:
	ldi R24,24
	ldi R25,0
	ldd R16,z+49
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	ldd R6,z+48
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+47
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+46
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldi R20,82
	ldi R21,82
	ldi R22,97
	ldi R23,65
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X229
	xjmp L376
X229:
X219:
	ldi R24,24
	ldi R25,0
	subi R30,235  ; addi 533
	sbci R31,253
	ldd R16,z+0
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	subi R30,236  ; addi 532
	sbci R31,253
	ldd R6,z+0
	subi R30,20
	sbci R31,2
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,237  ; addi 531
	sbci R31,253
	ldd R6,z+0
	subi R30,19
	sbci R31,2
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,238  ; addi 530
	sbci R31,253
	ldd R6,z+0
	subi R30,18
	sbci R31,2
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldi R20,114
	ldi R21,114
	ldi R22,65
	ldi R23,97
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X230
	xjmp L376
X230:
X220:
	.dbline 1557
; 			LD_WORD(fs->win+BS_55AA) == 0xAA55 &&
; 			LD_DWORD(fs->win+FSI_LeadSig) == 0x41615252 &&
; 			LD_DWORD(fs->win+FSI_StrucSig) == 0x61417272) {
	.dbline 1558
; 			fs->last_clust = LD_DWORD(fs->win+FSI_Nxt_Free);
	ldi R24,24
	ldi R25,0
	subi R30,227  ; addi 541
	sbci R31,253
	ldd R16,z+0
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	subi R30,228  ; addi 540
	sbci R31,253
	ldd R6,z+0
	subi R30,28
	sbci R31,2
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,229  ; addi 539
	sbci R31,253
	ldd R6,z+0
	subi R30,27
	sbci R31,2
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,230  ; addi 538
	sbci R31,253
	ldd R6,z+0
	subi R30,26
	sbci R31,2
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 1559
; 			fs->free_clust = LD_DWORD(fs->win+FSI_Free_Count);
	ldi R24,24
	ldi R25,0
	subi R30,231  ; addi 537
	sbci R31,253
	ldd R16,z+0
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	subi R30,232  ; addi 536
	sbci R31,253
	ldd R6,z+0
	subi R30,24
	sbci R31,2
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,233  ; addi 535
	sbci R31,253
	ldd R6,z+0
	subi R30,23
	sbci R31,2
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	subi R30,234  ; addi 534
	sbci R31,253
	ldd R6,z+0
	subi R30,22
	sbci R31,2
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	std z+14,R2
	std z+15,R3
	std z+16,R4
	std z+17,R5
	.dbline 1560
; 		}
L376:
	.dbline 1561
; 	}
L374:
	.dbline 1563
; #endif
; 	fs->fs_type = fmt;		/* FAT sub-type */
	movw R30,R12
	std z+0,R10
	.dbline 1564
; 	fs->winsect = 0;		/* Invalidate sector cache */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std z+42,R20
	std z+43,R21
	std z+44,R22
	std z+45,R23
	.dbline 1568
; #if _FS_RPATH
; 	fs->cdir = 0;			/* Current directory (root dir) */
; #endif
; 	fs->id = ++Fsid;		/* File system mount ID */
	lds R24,_Fsid
	lds R25,_Fsid+1
	adiw R24,1
	movw R10,R24
	sts _Fsid+1,R11
	sts _Fsid,R10
	std z+6,R11
	std z+5,R10
	.dbline 1569
; 	res = FR_OK;
	clr R10
	.dbline 1571
; 
; 	return res;
	mov R16,R10
	.dbline -2
L338:
	.dbline 0 ; func end
	adiw R28,25
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym r tbl 14 pc
	.dbsym r res 10 c
	.dbsym l mclst 17 l
	.dbsym l bsect 13 l
	.dbsym l tsect 9 l
	.dbsym r p 12 pkc
	.dbsym r stat 10 c
	.dbsym r vol 14 i
	.dbsym l fsize 5 l
	.dbsym r fmt 10 c
	.dbsym r fs 12 pS[_FATFS_]
	.dbsym l chk_wp 37 c
	.dbsym l rfs 35 ppS[_FATFS_]
	.dbsym r path 10 ppkc
	.dbend
	.dbfunc s validate _validate fc
;             id -> R10,R11
;             fs -> R20,R21
	.even
_validate:
	xcall push_xgset300C
	movw R10,R18
	movw R20,R16
	.dbline -1
	.dbline 1586
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Check if the file/dir object is valid or not                          */
; /*-----------------------------------------------------------------------*/
; 
; static
; FRESULT validate (	/* FR_OK(0): The object is valid, !=0: Invalid */
; 	FATFS *fs,		/* Pointer to the file system object */
; 	WORD id			/* Member id of the target object to be checked */
; )
; {
	.dbline 1587
; 	if (!fs || !fs->fs_type || fs->id != id)
	cpi R20,0
	cpc R20,R21
	breq L382
X231:
	movw R30,R20
	ldd R2,z+0
	tst R2
	breq L382
X232:
	ldd R2,z+5
	ldd R3,z+6
	cp R2,R10
	cpc R3,R11
	breq L379
X233:
L382:
	.dbline 1588
; 		return FR_INVALID_OBJECT;
	ldi R16,9
	xjmp L378
L379:
	.dbline 1590
; 
; 	ENTER_FF(fs);		/* Lock file system */
	.dbline 1592
; 
; 	if (disk_status(fs->drive) & STA_NOINIT)
	movw R30,R20
	ldd R16,z+1
	xcall _disk_status
	sbrs R16,0
	rjmp L383
X234:
	.dbline 1593
; 		return FR_NOT_READY;
	ldi R16,3
	xjmp L378
L383:
	.dbline 1595
; 
; 	return FR_OK;
	clr R16
	.dbline -2
L378:
	.dbline 0 ; func end
	xjmp pop_xgset300C
	.dbsym r id 10 s
	.dbsym r fs 20 pS[_FATFS_]
	.dbend
	.dbfunc e f_mount _f_mount fc
;            rfs -> R10,R11
;             fs -> R18,R19
;            vol -> R16
	.even
_f_mount::
	st -y,R10
	st -y,R11
	.dbline -1
	.dbline 1617
; }
; 
; 
; 
; 
; /*--------------------------------------------------------------------------
; 
;    Public Functions
; 
; --------------------------------------------------------------------------*/
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Mount/Unmount a Locical Drive                                         */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_mount (
; 	BYTE vol,		/* Logical drive number to be mounted/unmounted */
; 	FATFS *fs		/* Pointer to new file system object (NULL for unmount)*/
; )
; {
	.dbline 1621
; 	FATFS *rfs;
; 
; 
; 	if (vol >= _DRIVES)				/* Check if the drive number is valid */
	cpi R16,1
	brlo L386
X235:
	.dbline 1622
; 		return FR_INVALID_DRIVE;
	ldi R16,11
	xjmp L385
L386:
	.dbline 1623
; 	rfs = FatFs[vol];				/* Get current fs object */
	ldi R24,2
	mul R24,R16
	movw R30,R0
	ldi R24,<_FatFs
	ldi R25,>_FatFs
	add R30,R24
	adc R31,R25
	ldd R10,z+0
	ldd R11,z+1
	.dbline 1625
; 
; 	if (rfs) {
	tst R10
	brne X236
	tst R11
	breq L388
X236:
	.dbline 1625
	.dbline 1629
; #if _FS_REENTRANT					/* Discard sync object of the current volume */
; 		if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR;
; #endif
; 		rfs->fs_type = 0;			/* Clear old fs object */
	clr R2
	movw R30,R10
	std z+0,R2
	.dbline 1630
; 	}
L388:
	.dbline 1632
; 
; 	if (fs) {
	cpi R18,0
	cpc R18,R19
	breq L390
X237:
	.dbline 1632
	.dbline 1633
; 		fs->fs_type = 0;			/* Clear new fs object */
	clr R2
	movw R30,R18
	std z+0,R2
	.dbline 1637
; #if _FS_REENTRANT					/* Create sync object for the new volume */
; 		if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR;
; #endif
; 	}
L390:
	.dbline 1638
; 	FatFs[vol] = fs;				/* Register new fs object */
	ldi R24,2
	mul R24,R16
	movw R30,R0
	ldi R24,<_FatFs
	ldi R25,>_FatFs
	add R30,R24
	adc R31,R25
	std z+1,R19
	std z+0,R18
	.dbline 1640
; 
; 	return FR_OK;
	clr R16
	.dbline -2
L385:
	.dbline 0 ; func end
	ld R11,y+
	ld R10,y+
	ret
	.dbsym r rfs 10 pS[_FATFS_]
	.dbsym r fs 18 pS[_FATFS_]
	.dbsym r vol 16 c
	.dbend
	.dbfunc e f_open _f_open fc
	.dbstruct 0 544 _FIL_
	.dbfield 0 fs pS[_FATFS_]
	.dbfield 2 id s
	.dbfield 4 flag c
	.dbfield 5 csect c
	.dbfield 6 fptr l
	.dbfield 10 fsize l
	.dbfield 14 org_clust l
	.dbfield 18 curr_clust l
	.dbfield 22 dsect l
	.dbfield 26 dir_sect l
	.dbfield 30 dir_ptr pc
	.dbfield 32 buf A[512:512]c
	.dbend
;             cl -> y+40
;             ps -> y+36
;            sfn -> y+24
;            res -> R10
;             dj -> y+2
;            dir -> R12,R13
;           mode -> y+58
;           path -> y+56
;             fp -> y+54
	.even
_f_open::
	xcall push_arg4
	xcall push_xgsetF0FC
	sbiw R28,44
	.dbline -1
	.dbline 1655
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Open or Create a File                                                 */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_open (
; 	FIL *fp,			/* Pointer to the blank file object */
; 	const XCHAR *path,	/* Pointer to the file name */
; 	BYTE mode			/* Access mode and file open mode flags */
; )
; {
	.dbline 1662
; 	FRESULT res;
; 	DIR dj;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir;
; 
; 
; 	fp->fs = NULL;		/* Clear file object */
	clr R2
	clr R3
	ldd R30,y+54
	ldd R31,y+55
	std z+1,R3
	std z+0,R2
	.dbline 1664
; #if !_FS_READONLY
; 	mode &= (FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW);
	ldd R24,y+58
	andi R24,31
	std y+58,R24
	.dbline 1665
; 	res = auto_mount(&path, &dj.fs, (BYTE)(mode & (FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)));
	clr R25
	andi R24,30
	andi R25,0
	std y+0,R24
	movw R18,R28
	subi R18,254  ; offset = 2
	sbci R19,255
	movw R16,R28
	subi R16,200  ; offset = 56
	sbci R17,255
	xcall _auto_mount
	mov R10,R16
	.dbline 1670
; #else
; 	mode &= FA_READ;
; 	res = auto_mount(&path, &dj.fs, 0);
; #endif
; 	if (res != FR_OK) LEAVE_FF(dj.fs, res);
	tst R16
	breq L393
X238:
	.dbline 1670
	xjmp L392
L393:
	.dbline 1671
; 	INITBUF(dj, sfn, lfn);
	movw R24,R28
	adiw R24,24
	std y+23,R25
	std y+22,R24
	.dbline 1672
; 	res = follow_path(&dj, path);	/* Follow the file path */
	ldd R18,y+56
	ldd R19,y+57
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _follow_path
	mov R10,R16
	.dbline 1676
; 
; #if !_FS_READONLY
; 	/* Create or Open a file */
; 	if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) {
	ldd R24,y+58
	andi R24,28
	brne X256
	xjmp L396
X256:
X239:
	.dbline 1676
	.dbline 1679
; 		DWORD ps, cl;
; 
; 		if (res != FR_OK) {			/* No file, create new */
	tst R16
	breq L398
X240:
	.dbline 1679
	.dbline 1680
; 			if (res == FR_NO_FILE)	/* There is no file to open, create a new entry */
	cpi R16,4
	brne L400
X241:
	.dbline 1681
; 				res = dir_register(&dj);
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _dir_register
	mov R12,R16
	mov R10,R12
L400:
	.dbline 1682
; 			if (res != FR_OK) LEAVE_FF(dj.fs, res);
	tst R10
	breq L402
X242:
	.dbline 1682
	mov R16,R10
	xjmp L392
L402:
	.dbline 1683
; 			mode |= FA_CREATE_ALWAYS;
	ldd R24,y+58
	ori R24,8
	std y+58,R24
	.dbline 1684
; 			dir = dj.dir;			/* Created entry (SFN entry) */
	ldd R12,y+20
	ldd R13,y+21
	.dbline 1685
; 		}
	xjmp L399
L398:
	.dbline 1686
; 		else {						/* Any object is already existing */
	.dbline 1687
; 			if (mode & FA_CREATE_NEW)			/* Cannot create new */
	ldd R0,y+58
	sbrs R0,2
	rjmp L405
X243:
	.dbline 1688
; 				LEAVE_FF(dj.fs, FR_EXIST);
	ldi R16,8
	xjmp L392
L405:
	.dbline 1689
; 			dir = dj.dir;
	ldd R12,y+20
	ldd R13,y+21
	.dbline 1690
; 			if (!dir || (dir[DIR_Attr] & (AM_RDO | AM_DIR)))	/* Cannot overwrite it (R/O or DIR) */
	tst R12
	brne X244
	tst R13
	breq L410
X244:
	movw R30,R12
	ldd R24,z+11
	andi R24,17
	breq L408
X245:
L410:
	.dbline 1691
; 				LEAVE_FF(dj.fs, FR_DENIED);
	ldi R16,7
	xjmp L392
L408:
	.dbline 1692
; 			if (mode & FA_CREATE_ALWAYS) {		/* Resize it to zero on over write mode */
	ldd R0,y+58
	sbrs R0,3
	rjmp L411
X246:
	.dbline 1692
	.dbline 1693
; 				cl = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO);	/* Get start cluster */
	movw R30,R12
	ldd R2,z+26
	clr R3
	ldd R4,z+27
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,z+20
	clr R7
	ldd R8,z+21
	clr R9
	mov R9,R8
	clr R8
	or R8,R6
	or R9,R7
	movw R6,R8
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R6,R2
	or R7,R3
	or R8,R4
	or R9,R5
	std y+40,R6
	std y+41,R7
	std y+42,R8
	std y+43,R9
	.dbline 1694
; 				ST_WORD(dir+DIR_FstClusHI, 0);	/* cluster = 0 */
	clr R2
	std z+20,R2
	.dbline 1694
	std z+21,R2
	.dbline 1695
; 				ST_WORD(dir+DIR_FstClusLO, 0);
	std z+26,R2
	.dbline 1695
	std z+27,R2
	.dbline 1696
; 				ST_DWORD(dir+DIR_FileSize, 0);	/* size = 0 */
	std z+28,R2
	.dbline 1696
	std z+29,R2
	.dbline 1696
	std z+30,R2
	.dbline 1696
	std z+31,R2
	.dbline 1697
; 				dj.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+2
	ldd R31,y+3
	std z+4,R24
	.dbline 1698
; 				ps = dj.fs->winsect;			/* Remove the cluster chain */
	ldd R2,z+42
	ldd R3,z+43
	ldd R4,z+44
	ldd R5,z+45
	std y+36,R2
	std y+37,R3
	std y+38,R4
	std y+39,R5
	.dbline 1699
; 				if (cl) {
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+40
	ldd R3,y+41
	ldd R4,y+42
	ldd R5,y+43
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L413
X247:
	.dbline 1699
	.dbline 1700
; 					res = remove_chain(dj.fs, cl);
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+2
	ldd R17,y+3
	xcall _remove_chain
	mov R14,R16
	mov R10,R14
	.dbline 1701
; 					if (res) LEAVE_FF(dj.fs, res);
	tst R16
	breq L415
X248:
	.dbline 1701
	xjmp L392
L415:
	.dbline 1702
; 					dj.fs->last_clust = cl - 1;	/* Reuse the cluster hole */
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+40
	ldd R3,y+41
	ldd R4,y+42
	ldd R5,y+43
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	ldd R30,y+2
	ldd R31,y+3
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 1703
; 				}
L413:
	.dbline 1704
; 				res = move_window(dj.fs, ps);
	ldd R2,y+36
	ldd R3,y+37
	ldd R4,y+38
	ldd R5,y+39
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+2
	ldd R17,y+3
	xcall _move_window
	mov R14,R16
	mov R10,R14
	.dbline 1705
; 				if (res != FR_OK) LEAVE_FF(dj.fs, res);
	tst R16
	breq L417
X249:
	.dbline 1705
	xjmp L392
L417:
	.dbline 1706
; 			}
L411:
	.dbline 1707
; 		}
L399:
	.dbline 1708
; 		if (mode & FA_CREATE_ALWAYS) {
	ldd R0,y+58
	sbrs R0,3
	rjmp L397
X250:
	.dbline 1708
	.dbline 1709
; 			dir[DIR_Attr] = 0;					/* Reset attribute */
	clr R2
	movw R30,R12
	std z+11,R2
	.dbline 1710
; 			ps = get_fattime();
	xcall _get_fattime
	std y+36,R16
	std y+37,R17
	std y+38,R18
	std y+39,R19
	.dbline 1711
; 			ST_DWORD(dir+DIR_CrtTime, ps);		/* Created time */
	ldd R2,y+36
	ldd R3,y+37
	ldd R4,y+38
	ldd R5,y+39
	movw R30,R12
	std z+14,R2
	.dbline 1711
	mov R2,R3
	clr R3
	std z+15,R2
	.dbline 1711
	ldd R2,y+36
	ldd R3,y+37
	ldd R4,y+38
	ldd R5,y+39
	movw R2,R4
	clr R4
	clr R5
	std z+16,R2
	.dbline 1711
	ldi R24,24
	ldi R25,0
	ldd R16,y+36
	ldd R17,y+37
	ldd R18,y+38
	ldd R19,y+39
	st -y,R24
	xcall lsr32
	movw R30,R12
	std z+17,R16
	.dbline 1712
; 			dj.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+2
	ldd R31,y+3
	std z+4,R24
	.dbline 1713
; 			mode |= FA__WRITTEN;				/* Set file changed flag */
	ldd R24,y+58
	ori R24,32
	std y+58,R24
	.dbline 1714
; 		}
	.dbline 1715
; 	}
	xjmp L397
L396:
	.dbline 1717
; 	/* Open an existing file */
; 	else {
	.dbline 1719
; #endif /* !_FS_READONLY */
; 		if (res != FR_OK) LEAVE_FF(dj.fs, res);	/* Follow failed */
	tst R10
	breq L421
X251:
	.dbline 1719
	mov R16,R10
	xjmp L392
L421:
	.dbline 1720
; 		dir = dj.dir;
	ldd R12,y+20
	ldd R13,y+21
	.dbline 1721
; 		if (!dir || (dir[DIR_Attr] & AM_DIR))	/* It is a directory */
	tst R12
	brne X252
	tst R13
	breq L426
X252:
	movw R30,R12
	ldd R2,z+11
	sbrs R2,4
	rjmp L424
X253:
L426:
	.dbline 1722
; 			LEAVE_FF(dj.fs, FR_NO_FILE);
	ldi R16,4
	xjmp L392
L424:
	.dbline 1724
; #if !_FS_READONLY
; 		if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */
	ldd R0,y+58
	sbrs R0,1
	rjmp L427
X254:
	movw R30,R12
	ldd R2,z+11
	sbrs R2,0
	rjmp L427
X255:
	.dbline 1725
; 			LEAVE_FF(dj.fs, FR_DENIED);
	ldi R16,7
	xjmp L392
L427:
	.dbline 1726
; 	}
L397:
	.dbline 1727
; 	fp->dir_sect = dj.fs->winsect;		/* Pointer to the directory entry */
	ldd R30,y+2
	ldd R31,y+3
	ldd R2,z+42
	ldd R3,z+43
	ldd R4,z+44
	ldd R5,z+45
	ldd R30,y+54
	ldd R31,y+55
	std z+26,R2
	std z+27,R3
	std z+28,R4
	std z+29,R5
	.dbline 1728
; 	fp->dir_ptr = dj.dir;
	ldd R2,y+20
	ldd R3,y+21
	std z+31,R3
	std z+30,R2
	.dbline 1730
; #endif
; 	fp->flag = mode;					/* File access mode */
	ldd R0,y+58
	std z+4,R0
	.dbline 1731
; 	fp->org_clust =						/* File start cluster */
	movw R30,R12
	ldd R2,z+26
	clr R3
	ldd R4,z+27
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,z+20
	clr R7
	ldd R8,z+21
	clr R9
	mov R9,R8
	clr R8
	or R8,R6
	or R9,R7
	movw R6,R8
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R6,R2
	or R7,R3
	or R8,R4
	or R9,R5
	ldd R30,y+54
	ldd R31,y+55
	std z+14,R6
	std z+15,R7
	std z+16,R8
	std z+17,R9
	.dbline 1733
; 		((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO);
; 	fp->fsize = LD_DWORD(dir+DIR_FileSize);	/* File size */
	ldi R24,24
	ldi R25,0
	movw R30,R12
	ldd R16,z+31
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R12
	ldd R6,z+30
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+29
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+28
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R30,y+54
	ldd R31,y+55
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 1734
; 	fp->fptr = 0; fp->csect = 255;		/* File pointer */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std z+6,R20
	std z+7,R21
	std z+8,R22
	std z+9,R23
	.dbline 1734
	ldi R24,255
	std z+5,R24
	.dbline 1735
; 	fp->dsect = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std z+22,R20
	std z+23,R21
	std z+24,R22
	std z+25,R23
	.dbline 1736
; 	fp->fs = dj.fs; fp->id = dj.fs->id;	/* Owner file system object of the file */
	ldd R2,y+2
	ldd R3,y+3
	std z+1,R3
	std z+0,R2
	.dbline 1736
	movw R30,R2
	ldd R2,z+5
	ldd R3,z+6
	ldd R30,y+54
	ldd R31,y+55
	std z+3,R3
	std z+2,R2
	.dbline 1738
; 
; 	LEAVE_FF(dj.fs, FR_OK);
	clr R16
	.dbline -2
L392:
	.dbline 0 ; func end
	adiw R28,44
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym l cl 40 l
	.dbsym l ps 36 l
	.dbsym l sfn 24 A[12:12]c
	.dbsym r res 10 c
	.dbsym l dj 2 S[_DIR_]
	.dbsym r dir 12 pc
	.dbsym l mode 58 c
	.dbsym l path 56 pkc
	.dbsym l fp 54 pS[_FIL_]
	.dbend
	.dbfunc e f_read _f_read fc
;         remain -> y+13
;            res -> R10
;           clst -> y+9
;             cc -> R10,R11
;          rbuff -> R14,R15
;           sect -> y+5
;           rcnt -> R12,R13
;             br -> y+37
;            btr -> y+35
;           buff -> R10,R11
;             fp -> y+31
	.even
_f_read::
	xcall push_arg4
	xcall push_xgsetF0FC
	movw R10,R18
	sbiw R28,21
	.dbline -1
	.dbline 1754
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Read File                                                             */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_read (
; 	FIL *fp, 		/* Pointer to the file object */
; 	void *buff,		/* Pointer to data buffer */
; 	UINT btr,		/* Number of bytes to read */
; 	UINT *br		/* Pointer to number of bytes read */
; )
; {
	.dbline 1758
; 	FRESULT res;
; 	DWORD clst, sect, remain;
; 	UINT rcnt, cc;
; 	BYTE *rbuff = buff;
	movw R14,R10
	.dbline 1761
; 
; 
; 	*br = 0;
	clr R2
	clr R3
	ldd R30,y+37
	ldd R31,y+38
	std z+1,R3
	std z+0,R2
	.dbline 1763
; 
; 	res = validate(fp->fs, fp->id);					/* Check validity of the object */
	ldd R30,y+31
	ldd R31,y+32
	ldd R18,z+2
	ldd R19,z+3
	ldd R16,z+0
	ldd R17,z+1
	xcall _validate
	mov R10,R16
	.dbline 1764
; 	if (res != FR_OK) LEAVE_FF(fp->fs, res);
	tst R16
	breq L431
X257:
	.dbline 1764
	xjmp L430
L431:
	.dbline 1765
; 	if (fp->flag & FA__ERROR)						/* Check abort flag */
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+4
	sbrs R2,7
	rjmp L433
X258:
	.dbline 1766
; 		LEAVE_FF(fp->fs, FR_INT_ERR);
	ldi R16,2
	xjmp L430
L433:
	.dbline 1767
; 	if (!(fp->flag & FA_READ)) 						/* Check access mode */
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+4
	sbrc R2,0
	rjmp L435
X259:
	.dbline 1768
; 		LEAVE_FF(fp->fs, FR_DENIED);
	ldi R16,7
	xjmp L430
L435:
	.dbline 1769
; 	remain = fp->fsize - fp->fptr;
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	ldd R6,z+10
	ldd R7,z+11
	ldd R8,z+12
	ldd R9,z+13
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	std y+13,R6
	std y+14,R7
	std y+15,R8
	std y+16,R9
	.dbline 1770
; 	if (btr > remain) btr = (UINT)remain;			/* Truncate btr by remaining bytes */
	ldd R2,y+13
	ldd R3,y+14
	ldd R4,y+15
	ldd R5,y+16
	ldd R6,y+35
	ldd R7,y+36
	clr R8
	clr R9
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brlo X278
	xjmp L442
X278:
X260:
	.dbline 1770
	std y+36,R3
	std y+35,R2
	.dbline 1772
; 
; 	for ( ;  btr;									/* Repeat until all data transferred */
	xjmp L442
L439:
	.dbline 1773
; 		rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {
	.dbline 1774
; 		if ((fp->fptr % SS(fp->fs)) == 0) {			/* On the sector boundary? */
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X279
	xjmp L443
X279:
X261:
	.dbline 1774
	.dbline 1775
; 			if (fp->csect >= fp->fs->csize) {		/* On the cluster boundary? */
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R2,z+2
	ldd R30,y+31
	ldd R31,y+32
	ldd R3,z+5
	cp R3,R2
	brsh X280
	xjmp L445
X280:
X262:
	.dbline 1775
	.dbline 1776
; 				clst = (fp->fptr == 0) ?			/* On the top of the file? */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L447
X263:
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+17,R2
	std y+18,R3
	std y+19,R4
	std y+20,R5
	xjmp L448
L447:
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _get_fat
	std y+17,R16
	std y+18,R17
	std y+19,R18
	std y+20,R19
L448:
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	std y+9,R2
	std y+10,R3
	std y+11,R4
	std y+12,R5
	.dbline 1778
; 					fp->org_clust : get_fat(fp->fs, fp->curr_clust);
; 				if (clst <= 1) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R20,R2
	cpc R21,R3
	cpc R22,R4
	cpc R23,R5
	brlo L449
X264:
	.dbline 1778
	.dbline 1778
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1778
	ldi R16,2
	xjmp L430
L449:
	.dbline 1778
	.dbline 1779
; 				if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L451
X265:
	.dbline 1779
	.dbline 1779
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1779
	ldi R16,1
	xjmp L430
L451:
	.dbline 1779
	.dbline 1780
; 				fp->curr_clust = clst;				/* Update current cluster */
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	ldd R30,y+31
	ldd R31,y+32
	std z+18,R2
	std z+19,R3
	std z+20,R4
	std z+21,R5
	.dbline 1781
; 				fp->csect = 0;						/* Reset sector offset in the cluster */
	clr R2
	std z+5,R2
	.dbline 1782
; 			}
L445:
	.dbline 1783
; 			sect = clust2sect(fp->fs, fp->curr_clust);	/* Get current sector */
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _clust2sect
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
	.dbline 1784
; 			if (!sect) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L453
X266:
	.dbline 1784
	.dbline 1784
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1784
	ldi R16,2
	xjmp L430
L453:
	.dbline 1784
	.dbline 1785
; 			sect += fp->csect;
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+5
	clr R3
	clr R4
	clr R5
	ldd R6,y+5
	ldd R7,y+6
	ldd R8,y+7
	ldd R9,y+8
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+5,R6
	std y+6,R7
	std y+7,R8
	std y+8,R9
	.dbline 1786
; 			cc = btr / SS(fp->fs);					/* When remaining bytes >= sector size, */
	ldi R18,9
	ldi R19,0
	ldd R16,y+35
	ldd R17,y+36
	xcall lsr16
	movw R10,R16
	.dbline 1787
; 			if (cc) {								/* Read maximum contiguous sectors directly */
	cpi R16,0
	cpc R16,R17
	brne X281
	xjmp L455
X281:
X267:
	.dbline 1787
	.dbline 1788
; 				if (fp->csect + cc > fp->fs->csize)	/* Clip at cluster boundary */
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+5
	clr R3
	add R2,R16
	adc R3,R17
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R4,z+2
	clr R5
	cp R4,R2
	cpc R5,R3
	brsh L457
X268:
	.dbline 1789
; 					cc = fp->fs->csize - fp->csect;
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+5
	clr R3
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R10,z+2
	clr R11
	sub R10,R2
	sbc R11,R3
L457:
	.dbline 1790
; 				if (disk_read(fp->fs->drive, rbuff, sect, (BYTE)cc) != RES_OK)
	std y+4,R10
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R14
	ldd R30,y+31
	ldd R31,y+32
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_read
	mov R12,R16
	tst R16
	breq L459
X269:
	.dbline 1791
; 					ABORT(fp->fs, FR_DISK_ERR);
	.dbline 1791
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R12,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1791
	ldi R16,1
	xjmp L430
L459:
	.dbline 1791
	.dbline 1797
; #if !_FS_READONLY && _FS_MINIMIZE <= 2
; #if _FS_TINY
; 				if (fp->fs->wflag && fp->fs->winsect - sect < cc)		/* Replace one of the read sectors with cached data if it contains a dirty sector */
; 					mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs));
; #else
; 				if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc)	/* Replace one of the read sectors with cached data if it contains a dirty sector */
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+4
	sbrs R2,6
	rjmp L461
X270:
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R6,z+22
	ldd R7,z+23
	ldd R8,z+24
	ldd R9,z+25
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	movw R2,R10
	clr R4
	clr R5
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh L461
X271:
	.dbline 1798
; 					mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs));
	ldi R24,512
	ldi R25,2
	std y+1,R25
	std y+0,R24
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R6,z+22
	ldd R7,z+23
	ldd R8,z+24
	ldd R9,z+25
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	ldi R20,0
	ldi R21,2
	ldi R22,0
	ldi R23,0
	push R18
	push R19
	st -y,R9
	st -y,R8
	st -y,R7
	st -y,R6
	movw R16,R20
	movw R18,R22
	xcall empy32u
	pop R19
	pop R18
	add R16,R14
	adc R17,R15
	xcall _mem_cpy
L461:
	.dbline 1801
; #endif
; #endif
; 				fp->csect += (BYTE)cc;				/* Next sector address in the cluster */
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,5
	movw R30,R24
	ldd R2,z+0
	add R2,R10
	std z+0,R2
	.dbline 1802
; 				rcnt = SS(fp->fs) * cc;				/* Number of bytes transferred */
	ldi R16,512
	ldi R17,2
	movw R18,R10
	xcall empy16s
	movw R12,R16
	.dbline 1803
; 				continue;
	xjmp L440
L455:
	.dbline 1807
; 			}
; #if !_FS_TINY
; #if !_FS_READONLY
; 			if (fp->flag & FA__DIRTY) {			/* Write sector I/O buffer if needed */
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+4
	sbrs R2,6
	rjmp L463
X272:
	.dbline 1807
	.dbline 1808
; 				if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_write
	mov R10,R16
	tst R16
	breq L465
X273:
	.dbline 1809
; 					ABORT(fp->fs, FR_DISK_ERR);
	.dbline 1809
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1809
	ldi R16,1
	xjmp L430
L465:
	.dbline 1809
	.dbline 1810
; 				fp->flag &= ~FA__DIRTY;
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	andi R24,191
	std z+0,R24
	.dbline 1811
; 			}
L463:
	.dbline 1813
; #endif
; 			if (fp->dsect != sect) {			/* Fill sector buffer with file data */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R30,y+31
	ldd R31,y+32
	ldd R6,z+22
	ldd R7,z+23
	ldd R8,z+24
	ldd R9,z+25
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	breq L467
X274:
	.dbline 1813
	.dbline 1814
; 				if (disk_read(fp->fs->drive, fp->buf, sect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_read
	mov R10,R16
	tst R16
	breq L469
X275:
	.dbline 1815
; 					ABORT(fp->fs, FR_DISK_ERR);
	.dbline 1815
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1815
	ldi R16,1
	xjmp L430
L469:
	.dbline 1815
	.dbline 1816
; 			}
L467:
	.dbline 1818
; #endif
; 			fp->dsect = sect;
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R30,y+31
	ldd R31,y+32
	std z+22,R2
	std z+23,R3
	std z+24,R4
	std z+25,R5
	.dbline 1819
; 			fp->csect++;							/* Next sector address in the cluster */
	movw R24,R30
	adiw R24,5
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 1820
; 		}
L443:
	.dbline 1821
; 		rcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs));	/* Get partial sector data from sector buffer */
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,2
	ldi R22,0
	ldi R23,0
	sub R20,R2
	sbc R21,R3
	sbc R22,R4
	sbc R23,R5
	movw R12,R20
	.dbline 1822
; 		if (rcnt > btr) rcnt = btr;
	ldd R0,y+35
	ldd R1,y+36
	cp R0,R20
	cpc R1,R21
	brsh L471
X276:
	.dbline 1822
	movw R12,R0
L471:
	.dbline 1828
; #if _FS_TINY
; 		if (move_window(fp->fs, fp->dsect))			/* Move sector window */
; 			ABORT(fp->fs, FR_DISK_ERR);
; 		mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt);	/* Pick partial sector */
; #else
; 		mem_cpy(rbuff, &fp->buf[fp->fptr % SS(fp->fs)], rcnt);	/* Pick partial sector */
	std y+1,R13
	std y+0,R12
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R30,y+31
	ldd R31,y+32
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	movw R18,R2
	movw R24,R30
	adiw R24,32
	add R18,R24
	adc R19,R25
	movw R16,R14
	xcall _mem_cpy
	.dbline 1830
; #endif
; 	}
L440:
	.dbline 1773
	add R14,R12
	adc R15,R13
	ldd R24,y+31
	ldd R25,y+32
	adiw R24,6
	movw R10,R24
	movw R2,R12
	clr R4
	clr R5
	movw R30,R24
	ldd R6,z+0
	ldd R7,z+1
	ldd R8,z+2
	ldd R9,z+3
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+0,R6
	std z+1,R7
	std z+2,R8
	std z+3,R9
	ldd R30,y+37
	ldd R31,y+38
	ldd R2,z+0
	ldd R3,z+1
	add R2,R12
	adc R3,R13
	std z+1,R3
	std z+0,R2
	ldd R0,y+35
	ldd R1,y+36
	sub R0,R12
	sbc R1,R13
	std y+36,R1
	std y+35,R0
L442:
	.dbline 1772
	ldd R0,y+35
	ldd R1,y+36
	tst R0
	breq X282
	xjmp L439
X282:
	tst R1
	breq X283
	xjmp L439
X283:
X277:
	.dbline 1832
; 
; 	LEAVE_FF(fp->fs, FR_OK);
	clr R16
	.dbline -2
L430:
	.dbline 0 ; func end
	adiw R28,21
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym l remain 13 l
	.dbsym r res 10 c
	.dbsym l clst 9 l
	.dbsym r cc 10 i
	.dbsym r rbuff 14 pc
	.dbsym l sect 5 l
	.dbsym r rcnt 12 i
	.dbsym l br 37 pi
	.dbsym l btr 35 i
	.dbsym r buff 10 pV
	.dbsym l fp 31 pS[_FIL_]
	.dbend
	.dbfunc e f_write _f_write fc
;            res -> R10
;           clst -> y+9
;             cc -> R10,R11
;          wbuff -> R14,R15
;           sect -> y+5
;           wcnt -> R12,R13
;             bw -> y+33
;            btw -> y+31
;           buff -> R10,R11
;             fp -> y+27
	.even
_f_write::
	xcall push_arg4
	xcall push_xgsetF0FC
	movw R10,R18
	sbiw R28,17
	.dbline -1
	.dbline 1849
; }
; 
; 
; 
; 
; #if !_FS_READONLY
; /*-----------------------------------------------------------------------*/
; /* Write File                                                            */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_write (
; 	FIL *fp,			/* Pointer to the file object */
; 	const void *buff,	/* Pointer to the data to be written */
; 	UINT btw,			/* Number of bytes to write */
; 	UINT *bw			/* Pointer to number of bytes written */
; )
; {
	.dbline 1853
; 	FRESULT res;
; 	DWORD clst, sect;
; 	UINT wcnt, cc;
; 	const BYTE *wbuff = buff;
	movw R14,R10
	.dbline 1856
; 
; 
; 	*bw = 0;
	clr R2
	clr R3
	ldd R30,y+33
	ldd R31,y+34
	std z+1,R3
	std z+0,R2
	.dbline 1858
; 
; 	res = validate(fp->fs, fp->id);					/* Check validity of the object */
	ldd R30,y+27
	ldd R31,y+28
	ldd R18,z+2
	ldd R19,z+3
	ldd R16,z+0
	ldd R17,z+1
	xcall _validate
	mov R10,R16
	.dbline 1859
; 	if (res != FR_OK) LEAVE_FF(fp->fs, res);
	tst R16
	breq L474
X284:
	.dbline 1859
	xjmp L473
L474:
	.dbline 1860
; 	if (fp->flag & FA__ERROR)						/* Check abort flag */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+4
	sbrs R2,7
	rjmp L476
X285:
	.dbline 1861
; 		LEAVE_FF(fp->fs, FR_INT_ERR);
	ldi R16,2
	xjmp L473
L476:
	.dbline 1862
; 	if (!(fp->flag & FA_WRITE))						/* Check access mode */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+4
	sbrc R2,1
	rjmp L478
X286:
	.dbline 1863
; 		LEAVE_FF(fp->fs, FR_DENIED);
	ldi R16,7
	xjmp L473
L478:
	.dbline 1864
; 	if (fp->fsize + btw < fp->fsize) btw = 0;		/* File size cannot reach 4GB */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	std y+13,R2
	std y+14,R3
	std y+15,R4
	std y+16,R5
	ldd R2,y+31
	ldd R3,y+32
	clr R4
	clr R5
	ldd R6,y+13
	ldd R7,y+14
	ldd R8,y+15
	ldd R9,y+16
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	ldd R2,y+13
	ldd R3,y+14
	ldd R4,y+15
	ldd R5,y+16
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo X308
	xjmp L485
X308:
X287:
	.dbline 1864
	clr R0
	clr R1
	std y+32,R1
	std y+31,R0
	.dbline 1866
; 
; 	for ( ;  btw;									/* Repeat until all data transferred */
	xjmp L485
L482:
	.dbline 1867
; 		wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) {
	.dbline 1868
; 		if ((fp->fptr % SS(fp->fs)) == 0) {			/* On the sector boundary? */
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X309
	xjmp L486
X309:
X288:
	.dbline 1868
	.dbline 1869
; 			if (fp->csect >= fp->fs->csize) {		/* On the cluster boundary? */
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R2,z+2
	ldd R30,y+27
	ldd R31,y+28
	ldd R3,z+5
	cp R3,R2
	brsh X310
	xjmp L488
X310:
X289:
	.dbline 1869
	.dbline 1870
; 				if (fp->fptr == 0) {				/* On the top of the file? */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L490
X290:
	.dbline 1870
	.dbline 1871
; 					clst = fp->org_clust;			/* Follow from the origin */
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+9,R2
	std y+10,R3
	std y+11,R4
	std y+12,R5
	.dbline 1872
; 					if (clst == 0)					/* When there is no cluster chain, */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L491
X291:
	.dbline 1873
; 						fp->org_clust = clst = create_chain(fp->fs, 0);	/* Create a new cluster chain */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldd R30,y+27
	ldd R31,y+28
	ldd R16,z+0
	ldd R17,z+1
	xcall _create_chain
	std y+9,R16
	std y+10,R17
	std y+11,R18
	std y+12,R19
	ldd R30,y+27
	ldd R31,y+28
	std z+14,R16
	std z+15,R17
	std z+16,R18
	std z+17,R19
	.dbline 1874
; 				} else {							/* Middle or end of the file */
	xjmp L491
L490:
	.dbline 1874
	.dbline 1875
; 					clst = create_chain(fp->fs, fp->curr_clust);			/* Follow or streach cluster chain */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _create_chain
	std y+9,R16
	std y+10,R17
	std y+11,R18
	std y+12,R19
	.dbline 1876
; 				}
L491:
	.dbline 1877
; 				if (clst == 0) break;				/* Could not allocate a new cluster (disk full) */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L494
X292:
	.dbline 1877
	xjmp L484
L494:
	.dbline 1878
; 				if (clst == 1) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L496
X293:
	.dbline 1878
	.dbline 1878
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1878
	ldi R16,2
	xjmp L473
L496:
	.dbline 1878
	.dbline 1879
; 				if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L498
X294:
	.dbline 1879
	.dbline 1879
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1879
	ldi R16,1
	xjmp L473
L498:
	.dbline 1879
	.dbline 1880
; 				fp->curr_clust = clst;				/* Update current cluster */
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	ldd R30,y+27
	ldd R31,y+28
	std z+18,R2
	std z+19,R3
	std z+20,R4
	std z+21,R5
	.dbline 1881
; 				fp->csect = 0;						/* Reset sector address in the cluster */
	clr R2
	std z+5,R2
	.dbline 1882
; 			}
L488:
	.dbline 1887
; #if _FS_TINY
; 			if (fp->fs->winsect == fp->dsect && move_window(fp->fs, 0))	/* Write back data buffer prior to following direct transfer */
; 				ABORT(fp->fs, FR_DISK_ERR);
; #else
; 			if (fp->flag & FA__DIRTY) {		/* Write back data buffer prior to following direct transfer */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+4
	sbrs R2,6
	rjmp L500
X295:
	.dbline 1887
	.dbline 1888
; 				if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_write
	mov R10,R16
	tst R16
	breq L502
X296:
	.dbline 1889
; 					ABORT(fp->fs, FR_DISK_ERR);
	.dbline 1889
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1889
	ldi R16,1
	xjmp L473
L502:
	.dbline 1889
	.dbline 1890
; 				fp->flag &= ~FA__DIRTY;
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	andi R24,191
	std z+0,R24
	.dbline 1891
; 			}
L500:
	.dbline 1893
; #endif
; 			sect = clust2sect(fp->fs, fp->curr_clust);	/* Get current sector */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _clust2sect
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
	.dbline 1894
; 			if (!sect) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L504
X297:
	.dbline 1894
	.dbline 1894
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1894
	ldi R16,2
	xjmp L473
L504:
	.dbline 1894
	.dbline 1895
; 			sect += fp->csect;
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+5
	clr R3
	clr R4
	clr R5
	ldd R6,y+5
	ldd R7,y+6
	ldd R8,y+7
	ldd R9,y+8
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+5,R6
	std y+6,R7
	std y+7,R8
	std y+8,R9
	.dbline 1896
; 			cc = btw / SS(fp->fs);					/* When remaining bytes >= sector size, */
	ldi R18,9
	ldi R19,0
	ldd R16,y+31
	ldd R17,y+32
	xcall lsr16
	movw R10,R16
	.dbline 1897
; 			if (cc) {								/* Write maximum contiguous sectors directly */
	cpi R16,0
	cpc R16,R17
	brne X311
	xjmp L506
X311:
X298:
	.dbline 1897
	.dbline 1898
; 				if (fp->csect + cc > fp->fs->csize)	/* Clip at cluster boundary */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+5
	clr R3
	add R2,R16
	adc R3,R17
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R4,z+2
	clr R5
	cp R4,R2
	cpc R5,R3
	brsh L508
X299:
	.dbline 1899
; 					cc = fp->fs->csize - fp->csect;
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+5
	clr R3
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R10,z+2
	clr R11
	sub R10,R2
	sbc R11,R3
L508:
	.dbline 1900
; 				if (disk_write(fp->fs->drive, wbuff, sect, (BYTE)cc) != RES_OK)
	std y+4,R10
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R14
	ldd R30,y+27
	ldd R31,y+28
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_write
	mov R12,R16
	tst R16
	breq L510
X300:
	.dbline 1901
; 					ABORT(fp->fs, FR_DISK_ERR);
	.dbline 1901
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R12,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1901
	ldi R16,1
	xjmp L473
L510:
	.dbline 1901
	.dbline 1908
; #if _FS_TINY
; 				if (fp->fs->winsect - sect < cc) {	/* Refill sector cache if it gets dirty by the direct write */
; 					mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs));
; 					fp->fs->wflag = 0;
; 				}
; #else
; 				if (fp->dsect - sect < cc) {		/* Refill sector cache if it gets dirty by the direct write */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R30,y+27
	ldd R31,y+28
	ldd R6,z+22
	ldd R7,z+23
	ldd R8,z+24
	ldd R9,z+25
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	movw R2,R10
	clr R4
	clr R5
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh L512
X301:
	.dbline 1908
	.dbline 1909
; 					mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs));
	ldi R24,512
	ldi R25,2
	std y+1,R25
	std y+0,R24
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R6,z+22
	ldd R7,z+23
	ldd R8,z+24
	ldd R9,z+25
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	ldi R20,0
	ldi R21,2
	ldi R22,0
	ldi R23,0
	st -y,R9
	st -y,R8
	st -y,R7
	st -y,R6
	movw R16,R20
	movw R18,R22
	xcall empy32u
	movw R18,R16
	add R18,R14
	adc R19,R15
	ldd R16,y+27
	ldd R17,y+28
	subi R16,224  ; offset = 32
	sbci R17,255
	xcall _mem_cpy
	.dbline 1910
; 					fp->flag &= ~FA__DIRTY;
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R30,R24
	ldd R24,z+0
	andi R24,191
	std z+0,R24
	.dbline 1911
; 				}
L512:
	.dbline 1913
; #endif
; 				fp->csect += (BYTE)cc;				/* Next sector address in the cluster */
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,5
	movw R30,R24
	ldd R2,z+0
	add R2,R10
	std z+0,R2
	.dbline 1914
; 				wcnt = SS(fp->fs) * cc;				/* Number of bytes transferred */
	ldi R16,512
	ldi R17,2
	movw R18,R10
	xcall empy16s
	movw R12,R16
	.dbline 1915
; 				continue;
	xjmp L483
L506:
	.dbline 1923
; 			}
; #if _FS_TINY
; 			if (fp->fptr >= fp->fsize) {			/* Avoid silly buffer filling at growing edge */
; 				if (move_window(fp->fs, 0)) ABORT(fp->fs, FR_DISK_ERR);
; 				fp->fs->winsect = sect;
; 			}
; #else
; 			if (fp->dsect != sect) {				/* Fill sector buffer with file data */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R30,y+27
	ldd R31,y+28
	ldd R6,z+22
	ldd R7,z+23
	ldd R8,z+24
	ldd R9,z+25
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne X312
	xjmp L514
X312:
X302:
	.dbline 1923
	.dbline 1924
; 				if (fp->fptr < fp->fsize &&
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	ldd R6,z+6
	ldd R7,z+7
	ldd R8,z+8
	ldd R9,z+9
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh L516
X303:
	ldi R24,1
	std y+4,R24
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_read
	mov R10,R16
	tst R16
	breq L516
X304:
	.dbline 1926
; 					disk_read(fp->fs->drive, fp->buf, sect, 1) != RES_OK)
; 						ABORT(fp->fs, FR_DISK_ERR);
	.dbline 1926
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 1926
	ldi R16,1
	xjmp L473
L516:
	.dbline 1926
	.dbline 1927
; 			}
L514:
	.dbline 1929
; #endif
; 			fp->dsect = sect;
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	ldd R30,y+27
	ldd R31,y+28
	std z+22,R2
	std z+23,R3
	std z+24,R4
	std z+25,R5
	.dbline 1930
; 			fp->csect++;							/* Next sector address in the cluster */
	movw R24,R30
	adiw R24,5
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 1931
; 		}
L486:
	.dbline 1932
; 		wcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs));	/* Put partial sector into file I/O buffer */
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,2
	ldi R22,0
	ldi R23,0
	sub R20,R2
	sbc R21,R3
	sbc R22,R4
	sbc R23,R5
	movw R12,R20
	.dbline 1933
; 		if (wcnt > btw) wcnt = btw;
	ldd R0,y+31
	ldd R1,y+32
	cp R0,R20
	cpc R1,R21
	brsh L518
X305:
	.dbline 1933
	movw R12,R0
L518:
	.dbline 1940
; #if _FS_TINY
; 		if (move_window(fp->fs, fp->dsect))			/* Move sector window */
; 			ABORT(fp->fs, FR_DISK_ERR);
; 		mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt);	/* Fit partial sector */
; 		fp->fs->wflag = 1;
; #else
; 		mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt);	/* Fit partial sector */
	std y+1,R13
	std y+0,R12
	movw R18,R14
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	movw R16,R2
	movw R24,R30
	adiw R24,32
	add R16,R24
	adc R17,R25
	xcall _mem_cpy
	.dbline 1941
; 		fp->flag |= FA__DIRTY;
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,64
	std z+0,R24
	.dbline 1943
; #endif
; 	}
L483:
	.dbline 1867
	add R14,R12
	adc R15,R13
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,6
	movw R10,R24
	movw R2,R12
	clr R4
	clr R5
	movw R30,R24
	ldd R6,z+0
	ldd R7,z+1
	ldd R8,z+2
	ldd R9,z+3
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+0,R6
	std z+1,R7
	std z+2,R8
	std z+3,R9
	ldd R30,y+33
	ldd R31,y+34
	ldd R2,z+0
	ldd R3,z+1
	add R2,R12
	adc R3,R13
	std z+1,R3
	std z+0,R2
	ldd R0,y+31
	ldd R1,y+32
	sub R0,R12
	sbc R1,R13
	std y+32,R1
	std y+31,R0
L485:
	.dbline 1866
	ldd R0,y+31
	ldd R1,y+32
	tst R0
	breq X313
	xjmp L482
X313:
	tst R1
	breq X314
	xjmp L482
X314:
X306:
L484:
	.dbline 1945
; 
; 	if (fp->fptr > fp->fsize) fp->fsize = fp->fptr;	/* Update file size if needed */
	ldd R30,y+27
	ldd R31,y+28
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	ldd R6,z+6
	ldd R7,z+7
	ldd R8,z+8
	ldd R9,z+9
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brsh L520
X307:
	.dbline 1945
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
L520:
	.dbline 1946
; 	fp->flag |= FA__WRITTEN;						/* Set file changed flag */
	ldd R24,y+27
	ldd R25,y+28
	adiw R24,4
	movw R10,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,32
	std z+0,R24
	.dbline 1948
; 
; 	LEAVE_FF(fp->fs, FR_OK);
	clr R16
	.dbline -2
L473:
	.dbline 0 ; func end
	adiw R28,17
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym r res 10 c
	.dbsym l clst 9 l
	.dbsym r cc 10 i
	.dbsym r wbuff 14 pkc
	.dbsym l sect 5 l
	.dbsym r wcnt 12 i
	.dbsym l bw 33 pi
	.dbsym l btw 31 i
	.dbsym r buff 10 pkV
	.dbsym l fp 27 pS[_FIL_]
	.dbend
	.dbfunc e f_sync _f_sync fc
;            tim -> y+5
;            dir -> R22,R23
;            res -> R10
;             fp -> R20,R21
	.even
_f_sync::
	xcall push_xgsetF03C
	movw R20,R16
	sbiw R28,9
	.dbline -1
	.dbline 1961
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Synchronize the File Object                                           */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_sync (
; 	FIL *fp		/* Pointer to the file object */
; )
; {
	.dbline 1967
; 	FRESULT res;
; 	DWORD tim;
; 	BYTE *dir;
; 
; 
; 	res = validate(fp->fs, fp->id);		/* Check validity of the object */
	movw R30,R20
	ldd R18,z+2
	ldd R19,z+3
	ldd R16,z+0
	ldd R17,z+1
	xcall _validate
	mov R10,R16
	.dbline 1968
; 	if (res == FR_OK) {
	tst R16
	breq X320
	xjmp L523
X320:
X315:
	.dbline 1968
	.dbline 1969
; 		if (fp->flag & FA__WRITTEN) {	/* Has the file been written? */
	movw R30,R20
	ldd R2,z+4
	sbrs R2,5
	rjmp L525
X316:
	.dbline 1969
	.dbline 1971
; #if !_FS_TINY	/* Write-back dirty buffer */
; 			if (fp->flag & FA__DIRTY) {
	sbrs R2,6
	rjmp L527
X317:
	.dbline 1971
	.dbline 1972
; 				if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_write
	tst R16
	breq L529
X318:
	.dbline 1973
; 					LEAVE_FF(fp->fs, FR_DISK_ERR);
	ldi R16,1
	xjmp L522
L529:
	.dbline 1974
; 				fp->flag &= ~FA__DIRTY;
	movw R22,R20
	subi R22,252  ; offset = 4
	sbci R23,255
	movw R30,R22
	ldd R24,z+0
	andi R24,191
	std z+0,R24
	.dbline 1975
; 			}
L527:
	.dbline 1978
; #endif
; 			/* Update the directory entry */
; 			res = move_window(fp->fs, fp->dir_sect);
	movw R30,R20
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R12,R16
	mov R10,R12
	.dbline 1979
; 			if (res == FR_OK) {
	tst R16
	breq X321
	xjmp L531
X321:
X319:
	.dbline 1979
	.dbline 1980
; 				dir = fp->dir_ptr;
	movw R30,R20
	ldd R22,z+30
	ldd R23,z+31
	.dbline 1981
; 				dir[DIR_Attr] |= AM_ARC;					/* Set archive bit */
	movw R24,R22
	adiw R24,11
	movw R30,R24
	ldd R24,z+0
	ori R24,32
	std z+0,R24
	.dbline 1982
; 				ST_DWORD(dir+DIR_FileSize, fp->fsize);		/* Update file size */
	movw R30,R20
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	movw R30,R22
	std z+28,R2
	.dbline 1982
	movw R30,R20
	ldd R2,z+10
	ldd R3,z+11
	mov R2,R3
	clr R3
	movw R30,R22
	std z+29,R2
	.dbline 1982
	movw R30,R20
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	movw R2,R4
	clr R4
	clr R5
	movw R30,R22
	std z+30,R2
	.dbline 1982
	ldi R24,24
	ldi R25,0
	movw R30,R20
	ldd R16,z+10
	ldd R17,z+11
	ldd R18,z+12
	ldd R19,z+13
	st -y,R24
	xcall lsr32
	movw R30,R22
	std z+31,R16
	.dbline 1983
; 				ST_WORD(dir+DIR_FstClusLO, fp->org_clust);	/* Update start cluster */
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	movw R30,R22
	std z+26,R2
	.dbline 1983
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	mov R2,R3
	clr R3
	movw R30,R22
	std z+27,R2
	.dbline 1984
; 				ST_WORD(dir+DIR_FstClusHI, fp->org_clust >> 16);
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	movw R2,R4
	clr R4
	clr R5
	movw R30,R22
	std z+20,R2
	.dbline 1984
	movw R30,R20
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	movw R2,R4
	mov R2,R3
	clr R3
	movw R30,R22
	std z+21,R2
	.dbline 1985
; 				tim = get_fattime();			/* Updated time */
	xcall _get_fattime
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
	.dbline 1986
; 				ST_DWORD(dir+DIR_WrtTime, tim);
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R22
	std z+22,R2
	.dbline 1986
	mov R2,R3
	clr R3
	std z+23,R2
	.dbline 1986
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R2,R4
	clr R4
	clr R5
	std z+24,R2
	.dbline 1986
	ldi R24,24
	ldi R25,0
	ldd R16,y+5
	ldd R17,y+6
	ldd R18,y+7
	ldd R19,y+8
	st -y,R24
	xcall lsr32
	movw R30,R22
	std z+25,R16
	.dbline 1987
; 				fp->flag &= ~FA__WRITTEN;
	movw R22,R20
	subi R22,252  ; offset = 4
	sbci R23,255
	movw R30,R22
	ldd R24,z+0
	andi R24,223
	std z+0,R24
	.dbline 1988
; 				fp->fs->wflag = 1;
	ldi R24,1
	movw R30,R20
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	std z+4,R24
	.dbline 1989
; 				res = sync(fp->fs);
	movw R30,R20
	ldd R16,z+0
	ldd R17,z+1
	xcall _sync
	mov R12,R16
	mov R10,R12
	.dbline 1990
; 			}
L531:
	.dbline 1991
; 		}
L525:
	.dbline 1992
; 	}
L523:
	.dbline 1994
; 
; 	LEAVE_FF(fp->fs, res);
	mov R16,R10
	.dbline -2
L522:
	.dbline 0 ; func end
	adiw R28,9
	xjmp pop_xgsetF03C
	.dbsym l tim 5 l
	.dbsym r dir 22 pc
	.dbsym r res 10 c
	.dbsym r fp 20 pS[_FIL_]
	.dbend
	.dbfunc e f_close _f_close fc
;            res -> R10
;             fp -> R12,R13
	.even
_f_close::
	xcall push_xgset003C
	movw R12,R16
	.dbline -1
	.dbline 2009
; }
; 
; #endif /* !_FS_READONLY */
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Close File                                                            */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_close (
; 	FIL *fp		/* Pointer to the file object to be closed */
; )
; {
	.dbline 2018
; 	FRESULT res;
; 
; 
; #if _FS_READONLY
; 	res = validate(fp->fs, fp->id);
; 	if (res == FR_OK) fp->fs = NULL;
; 	LEAVE_FF(fp->fs, res);
; #else
; 	res = f_sync(fp);
	movw R16,R12
	xcall _f_sync
	mov R10,R16
	.dbline 2019
; 	if (res == FR_OK) fp->fs = NULL;
	tst R16
	brne L534
X322:
	.dbline 2019
	clr R2
	clr R3
	movw R30,R12
	std z+1,R3
	std z+0,R2
L534:
	.dbline 2020
; 	return res;
	mov R16,R10
	.dbline -2
L533:
	.dbline 0 ; func end
	xjmp pop_xgset003C
	.dbsym r res 10 c
	.dbsym r fp 12 pS[_FIL_]
	.dbend
	.dbfunc e f_lseek _f_lseek fc
;          ifptr -> y+17
;          nsect -> y+13
;            res -> R10
;            bcs -> y+9
;           clst -> y+5
;            ofs -> y+31
;             fp -> R12,R13
	.even
_f_lseek::
	st -y,r19
	st -y,r18
	xcall push_xgsetF0FC
	movw R12,R16
	sbiw R28,21
	.dbline -1
	.dbline 2091
; #endif
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Change Current Drive/Directory                                        */
; /*-----------------------------------------------------------------------*/
; 
; #if _FS_RPATH
; 
; FRESULT f_chdrive (
; 	BYTE drv		/* Drive number */
; )
; {
; 	if (drv >= _DRIVES) return FR_INVALID_DRIVE;
; 
; 	Drive = drv;
; 
; 	return FR_OK;
; }
; 
; 
; 
; 
; FRESULT f_chdir (
; 	const XCHAR *path	/* Pointer to the directory path */
; )
; {
; 	FRESULT res;
; 	DIR dj;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir;
; 
; 
; 	res = auto_mount(&path, &dj.fs, 0);
; 	if (res == FR_OK) {
; 		INITBUF(dj, sfn, lfn);
; 		res = follow_path(&dj, path);		/* Follow the file path */
; 		if (res == FR_OK) {					/* Follow completed */
; 			dir = dj.dir;					/* Pointer to the entry */
; 			if (!dir) {
; 				dj.fs->cdir = 0;			/* No entry (root dir) */
; 			} else {
; 				if (dir[DIR_Attr] & AM_DIR)	/* Reached to the dir */
; 					dj.fs->cdir = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO);
; 				else
; 					res = FR_NO_PATH;		/* Could not reach the dir (it is a file) */
; 			}
; 		}
; 		if (res == FR_NO_FILE) res = FR_NO_PATH;
; 	}
; 
; 	LEAVE_FF(dj.fs, res);
; }
; 
; #endif
; 
; 
; 
; #if _FS_MINIMIZE <= 2
; /*-----------------------------------------------------------------------*/
; /* Seek File R/W Pointer                                                 */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_lseek (
; 	FIL *fp,		/* Pointer to the file object */
; 	DWORD ofs		/* File pointer from top of file */
; )
; {
	.dbline 2096
; 	FRESULT res;
; 	DWORD clst, bcs, nsect, ifptr;
; 
; 
; 	res = validate(fp->fs, fp->id);		/* Check validity of the object */
	movw R30,R12
	ldd R18,z+2
	ldd R19,z+3
	ldd R16,z+0
	ldd R17,z+1
	xcall _validate
	mov R10,R16
	.dbline 2097
; 	if (res != FR_OK) LEAVE_FF(fp->fs, res);
	tst R16
	breq L537
X323:
	.dbline 2097
	xjmp L536
L537:
	.dbline 2098
; 	if (fp->flag & FA__ERROR)			/* Check abort flag */
	movw R30,R12
	ldd R2,z+4
	sbrs R2,7
	rjmp L539
X324:
	.dbline 2099
; 		LEAVE_FF(fp->fs, FR_INT_ERR);
	ldi R16,2
	xjmp L536
L539:
	.dbline 2100
; 	if (ofs > fp->fsize					/* In read-only mode, clip offset with the file size */
	movw R30,R12
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	ldd R6,y+31
	ldd R7,y+32
	ldd R8,y+33
	ldd R9,y+34
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brsh L541
X325:
	ldd R2,z+4
	sbrc R2,1
	rjmp L541
X326:
	.dbline 2104
; #if !_FS_READONLY
; 		 && !(fp->flag & FA_WRITE)
; #endif
; 		) ofs = fp->fsize;
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	std y+31,R2
	std y+32,R3
	std y+33,R4
	std y+34,R5
L541:
	.dbline 2106
; 
; 	ifptr = fp->fptr;
	movw R30,R12
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	std y+17,R2
	std y+18,R3
	std y+19,R4
	std y+20,R5
	.dbline 2107
; 	fp->fptr = nsect = 0; fp->csect = 255;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+13,R20
	std y+14,R21
	std y+15,R22
	std y+16,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std z+6,R20
	std z+7,R21
	std z+8,R22
	std z+9,R23
	.dbline 2107
	ldi R24,255
	std z+5,R24
	.dbline 2108
; 	if (ofs > 0) {
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+31
	ldd R3,y+32
	ldd R4,y+33
	ldd R5,y+34
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne X348
	xjmp L543
X348:
X327:
	.dbline 2108
	.dbline 2109
; 		bcs = (DWORD)fp->fs->csize * SS(fp->fs);	/* Cluster size (byte) */
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R2,z+2
	clr R3
	clr R4
	clr R5
	ldi R20,0
	ldi R21,2
	ldi R22,0
	ldi R23,0
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	movw R16,R20
	movw R18,R22
	xcall empy32u
	std y+9,R16
	std y+10,R17
	std y+11,R18
	std y+12,R19
	.dbline 2110
; 		if (ifptr > 0 &&
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+17
	ldd R3,y+18
	ldd R4,y+19
	ldd R5,y+20
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne X349
	xjmp L545
X349:
X328:
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R16,R2
	movw R18,R4
	sub R16,R20
	sbc R17,R21
	sbc R18,R22
	sbc R19,R23
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall div32u
	movw R2,R16
	movw R4,R18
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+31
	ldd R17,y+32
	ldd R18,y+33
	ldd R19,y+34
	sub R16,R20
	sbc R17,R21
	sbc R18,R22
	sbc R19,R23
	ldd R6,y+9
	ldd R7,y+10
	ldd R8,y+11
	ldd R9,y+12
	st -y,R9
	st -y,R8
	st -y,R7
	st -y,R6
	xcall div32u
	cp R16,R2
	cpc R17,R3
	cpc R18,R4
	cpc R19,R5
	brsh X350
	xjmp L545
X350:
X329:
	.dbline 2111
; 			(ofs - 1) / bcs >= (ifptr - 1) / bcs) {	/* When seek to same or following cluster, */
	.dbline 2112
; 			fp->fptr = (ifptr - 1) & ~(bcs - 1);	/* start from the current cluster */
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	com R2
	com R3
	com R4
	com R5
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R6,y+17
	ldd R7,y+18
	ldd R8,y+19
	ldd R9,y+20
	sub R6,R20
	sbc R7,R21
	sbc R8,R22
	sbc R9,R23
	and R6,R2
	and R7,R3
	and R8,R4
	and R9,R5
	movw R30,R12
	std z+6,R6
	std z+7,R7
	std z+8,R8
	std z+9,R9
	.dbline 2113
; 			ofs -= fp->fptr;
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	ldd R6,y+31
	ldd R7,y+32
	ldd R8,y+33
	ldd R9,y+34
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	std y+31,R6
	std y+32,R7
	std y+33,R8
	std y+34,R9
	.dbline 2114
; 			clst = fp->curr_clust;
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+5,R2
	std y+6,R3
	std y+7,R4
	std y+8,R5
	.dbline 2115
; 		} else {									/* When seek to back cluster, */
	xjmp L546
L545:
	.dbline 2115
	.dbline 2116
; 			clst = fp->org_clust;					/* start from the first cluster */
	movw R30,R12
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+5,R2
	std y+6,R3
	std y+7,R4
	std y+8,R5
	.dbline 2118
; #if !_FS_READONLY
; 			if (clst == 0) {						/* If no cluster chain, create a new chain */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X351
	xjmp L547
X351:
X330:
	.dbline 2118
	.dbline 2119
; 				clst = create_chain(fp->fs, 0);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldd R16,z+0
	ldd R17,z+1
	xcall _create_chain
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
	.dbline 2120
; 				if (clst == 1) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L549
X331:
	.dbline 2120
	.dbline 2120
	movw R24,R12
	adiw R24,4
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2120
	ldi R16,2
	xjmp L536
L549:
	.dbline 2120
	.dbline 2121
; 				if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L551
X332:
	.dbline 2121
	.dbline 2121
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2121
	ldi R16,1
	xjmp L536
L551:
	.dbline 2121
	.dbline 2122
; 				fp->org_clust = clst;
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R12
	std z+14,R2
	std z+15,R3
	std z+16,R4
	std z+17,R5
	.dbline 2123
; 			}
L547:
	.dbline 2125
; #endif
; 			fp->curr_clust = clst;
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R12
	std z+18,R2
	std z+19,R3
	std z+20,R4
	std z+21,R5
	.dbline 2126
; 		}
L546:
	.dbline 2127
; 		if (clst != 0) {
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne X352
	xjmp L553
X352:
X333:
	.dbline 2127
	xjmp L556
L555:
	.dbline 2128
; 			while (ofs > bcs) {						/* Cluster following loop */
	.dbline 2130
; #if !_FS_READONLY
; 				if (fp->flag & FA_WRITE) {			/* Check if in write mode or not */
	movw R30,R12
	ldd R2,z+4
	sbrs R2,1
	rjmp L558
X334:
	.dbline 2130
	.dbline 2131
; 					clst = create_chain(fp->fs, clst);	/* Force streached if in write mode */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _create_chain
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
	.dbline 2132
; 					if (clst == 0) {				/* When disk gets full, clip file size */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L559
X335:
	.dbline 2132
	.dbline 2133
; 						ofs = bcs; break;
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	std y+31,R2
	std y+32,R3
	std y+33,R4
	std y+34,R5
	.dbline 2133
	xjmp L557
L558:
	.dbline 2137
; 					}
; 				} else
; #endif
; 					clst = get_fat(fp->fs, clst);	/* Follow cluster chain if not in write mode */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R30,R12
	ldd R16,z+0
	ldd R17,z+1
	xcall _get_fat
	std y+5,R16
	std y+6,R17
	std y+7,R18
	std y+8,R19
L559:
	.dbline 2138
; 				if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L562
X336:
	.dbline 2138
	.dbline 2138
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2138
	ldi R16,1
	xjmp L536
L562:
	.dbline 2138
	.dbline 2139
; 				if (clst <= 1 || clst >= fp->fs->max_clust) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	cp R20,R2
	cpc R21,R3
	cpc R22,R4
	cpc R23,R5
	brsh L566
X337:
	movw R30,R12
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R6,y+5
	ldd R7,y+6
	ldd R8,y+7
	ldd R9,y+8
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo L564
X338:
L566:
	.dbline 2139
	.dbline 2139
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2139
	ldi R16,2
	xjmp L536
L564:
	.dbline 2139
	.dbline 2140
; 				fp->curr_clust = clst;
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	movw R30,R12
	std z+18,R2
	std z+19,R3
	std z+20,R4
	std z+21,R5
	.dbline 2141
; 				fp->fptr += bcs;
	movw R24,R30
	adiw R24,6
	movw R14,R24
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	movw R30,R24
	ldd R6,z+0
	ldd R7,z+1
	ldd R8,z+2
	ldd R9,z+3
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+0,R6
	std z+1,R7
	std z+2,R8
	std z+3,R9
	.dbline 2142
; 				ofs -= bcs;
	ldd R6,y+31
	ldd R7,y+32
	ldd R8,y+33
	ldd R9,y+34
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	std y+31,R6
	std y+32,R7
	std y+33,R8
	std y+34,R9
	.dbline 2143
; 			}
L556:
	.dbline 2128
	ldd R2,y+9
	ldd R3,y+10
	ldd R4,y+11
	ldd R5,y+12
	ldd R6,y+31
	ldd R7,y+32
	ldd R8,y+33
	ldd R9,y+34
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brsh X353
	xjmp L555
X353:
X339:
L557:
	.dbline 2144
; 			fp->fptr += ofs;
	movw R24,R12
	adiw R24,6
	movw R14,R24
	ldd R2,y+31
	ldd R3,y+32
	ldd R4,y+33
	ldd R5,y+34
	movw R30,R24
	ldd R6,z+0
	ldd R7,z+1
	ldd R8,z+2
	ldd R9,z+3
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std z+0,R6
	std z+1,R7
	std z+2,R8
	std z+3,R9
	.dbline 2145
; 			fp->csect = (BYTE)(ofs / SS(fp->fs));	/* Sector offset in the cluster */
	ldi R24,9
	ldi R25,0
	movw R16,R2
	movw R18,R4
	st -y,R24
	xcall lsr32
	movw R30,R12
	std z+5,R16
	.dbline 2146
; 			if (ofs % SS(fp->fs)) {
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	ldd R2,y+31
	ldd R3,y+32
	ldd R4,y+33
	ldd R5,y+34
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne X354
	xjmp L567
X354:
X340:
	.dbline 2146
	.dbline 2147
; 				nsect = clust2sect(fp->fs, clst);	/* Current sector */
	ldd R2,y+5
	ldd R3,y+6
	ldd R4,y+7
	ldd R5,y+8
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _clust2sect
	std y+13,R16
	std y+14,R17
	std y+15,R18
	std y+16,R19
	.dbline 2148
; 				if (!nsect) ABORT(fp->fs, FR_INT_ERR);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+13
	ldd R3,y+14
	ldd R4,y+15
	ldd R5,y+16
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L569
X341:
	.dbline 2148
	.dbline 2148
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2148
	ldi R16,2
	xjmp L536
L569:
	.dbline 2148
	.dbline 2149
; 				nsect += fp->csect;
	movw R30,R12
	ldd R2,z+5
	clr R3
	clr R4
	clr R5
	ldd R6,y+13
	ldd R7,y+14
	ldd R8,y+15
	ldd R9,y+16
	add R6,R2
	adc R7,R3
	adc R8,R4
	adc R9,R5
	std y+13,R6
	std y+14,R7
	std y+15,R8
	std y+16,R9
	.dbline 2150
; 				fp->csect++;
	movw R24,R30
	adiw R24,5
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 2151
; 			}
L567:
	.dbline 2152
; 		}
L553:
	.dbline 2153
; 	}
L543:
	.dbline 2154
; 	if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) {
	ldi R20,255
	ldi R21,1
	ldi R22,0
	ldi R23,0
	movw R30,R12
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne X355
	xjmp L571
X355:
X342:
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	ldd R6,y+13
	ldd R7,y+14
	ldd R8,y+15
	ldd R9,y+16
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne X356
	xjmp L571
X356:
X343:
	.dbline 2154
	.dbline 2157
; #if !_FS_TINY
; #if !_FS_READONLY
; 		if (fp->flag & FA__DIRTY) {			/* Write-back dirty buffer if needed */
	ldd R2,z+4
	sbrs R2,6
	rjmp L573
X344:
	.dbline 2157
	.dbline 2158
; 			if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R30
	subi R18,224  ; offset = 32
	sbci R19,255
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_write
	mov R14,R16
	tst R16
	breq L575
X345:
	.dbline 2159
; 				ABORT(fp->fs, FR_DISK_ERR);
	.dbline 2159
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2159
	ldi R16,1
	xjmp L536
L575:
	.dbline 2159
	.dbline 2160
; 			fp->flag &= ~FA__DIRTY;
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	andi R24,191
	std z+0,R24
	.dbline 2161
; 		}
L573:
	.dbline 2163
; #endif
; 		if (disk_read(fp->fs->drive, fp->buf, nsect, 1) != RES_OK)
	ldi R24,1
	std y+4,R24
	ldd R2,y+13
	ldd R3,y+14
	ldd R4,y+15
	ldd R5,y+16
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	movw R18,R12
	subi R18,224  ; offset = 32
	sbci R19,255
	movw R30,R12
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	ldd R16,z+1
	xcall _disk_read
	mov R14,R16
	tst R16
	breq L577
X346:
	.dbline 2164
; 			ABORT(fp->fs, FR_DISK_ERR);
	.dbline 2164
	movw R24,R12
	adiw R24,4
	movw R14,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
	.dbline 2164
	ldi R16,1
	xjmp L536
L577:
	.dbline 2164
	.dbline 2166
; #endif
; 		fp->dsect = nsect;
	ldd R2,y+13
	ldd R3,y+14
	ldd R4,y+15
	ldd R5,y+16
	movw R30,R12
	std z+22,R2
	std z+23,R3
	std z+24,R4
	std z+25,R5
	.dbline 2167
; 	}
L571:
	.dbline 2169
; #if !_FS_READONLY
; 	if (fp->fptr > fp->fsize) {			/* Set changed flag if the file size is extended */
	movw R30,R12
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	ldd R6,z+6
	ldd R7,z+7
	ldd R8,z+8
	ldd R9,z+9
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brsh L579
X347:
	.dbline 2169
	.dbline 2170
; 		fp->fsize = fp->fptr;
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 2171
; 		fp->flag |= FA__WRITTEN;
	movw R24,R30
	adiw R24,4
	movw R12,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,32
	std z+0,R24
	.dbline 2172
; 	}
L579:
	.dbline 2175
; #endif
; 
; 	LEAVE_FF(fp->fs, res);
	mov R16,R10
	.dbline -2
L536:
	.dbline 0 ; func end
	adiw R28,21
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym l ifptr 17 l
	.dbsym l nsect 13 l
	.dbsym r res 10 c
	.dbsym l bcs 9 l
	.dbsym l clst 5 l
	.dbsym l ofs 31 l
	.dbsym r fp 12 pS[_FIL_]
	.dbend
	.dbfunc e f_opendir _f_opendir fc
;            sfn -> y+1
;            dir -> R10,R11
;            res -> R20
;           path -> y+19
;             dj -> R22,R23
	.even
_f_opendir::
	st -y,r19
	st -y,r18
	xcall push_xgsetF00C
	movw R22,R16
	sbiw R28,13
	.dbline -1
	.dbline 2190
; }
; 
; 
; 
; 
; #if _FS_MINIMIZE <= 1
; /*-----------------------------------------------------------------------*/
; /* Create a Directroy Object                                             */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_opendir (
; 	DIR *dj,			/* Pointer to directory object to create */
; 	const XCHAR *path	/* Pointer to the directory path */
; )
; {
	.dbline 2196
; 	FRESULT res;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir;
; 
; 
; 	res = auto_mount(&path, &dj->fs, 0);
	clr R2
	std y+0,R2
	movw R18,R22
	movw R16,R28
	subi R16,237  ; offset = 19
	sbci R17,255
	xcall _auto_mount
	mov R20,R16
	.dbline 2197
; 	if (res == FR_OK) {
	tst R16
	breq X363
	xjmp L582
X363:
X357:
	.dbline 2197
	.dbline 2198
; 		INITBUF((*dj), sfn, lfn);
	movw R24,R28
	adiw R24,1
	movw R30,R22
	std z+21,R25
	std z+20,R24
	.dbline 2199
; 		res = follow_path(dj, path);			/* Follow the path to the directory */
	ldd R18,y+19
	ldd R19,y+20
	movw R16,R30
	xcall _follow_path
	mov R20,R16
	.dbline 2200
; 		if (res == FR_OK) {						/* Follow completed */
	tst R16
	breq X364
	xjmp L584
X364:
X358:
	.dbline 2200
	.dbline 2201
; 			dir = dj->dir;
	movw R30,R22
	ldd R10,z+18
	ldd R11,z+19
	.dbline 2202
; 			if (dir) {							/* It is not the root dir */
	tst R10
	brne X359
	tst R11
	brne X365
	xjmp L586
X365:
X359:
	.dbline 2202
	.dbline 2203
; 				if (dir[DIR_Attr] & AM_DIR) {	/* The object is a directory */
	movw R30,R10
	ldd R2,z+11
	sbrs R2,4
	rjmp L588
X360:
	.dbline 2203
	.dbline 2204
; 					dj->sclust = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO);
	ldd R2,z+26
	clr R3
	ldd R4,z+27
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,z+20
	clr R7
	ldd R8,z+21
	clr R9
	mov R9,R8
	clr R8
	or R8,R6
	or R9,R7
	movw R6,R8
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R6,R2
	or R7,R3
	or R8,R4
	or R9,R5
	movw R30,R22
	std z+6,R6
	std z+7,R7
	std z+8,R8
	std z+9,R9
	.dbline 2205
; 				} else {						/* The object is not a directory */
	xjmp L589
L588:
	.dbline 2205
	.dbline 2206
; 					res = FR_NO_PATH;
	ldi R20,5
	.dbline 2207
; 				}
L589:
	.dbline 2208
; 			}
L586:
	.dbline 2209
; 			if (res == FR_OK) {
	tst R20
	brne L590
X361:
	.dbline 2209
	.dbline 2210
; 				dj->id = dj->fs->id;
	movw R30,R22
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,5
	ld R2,x+
	ld R3,x
	std z+3,R3
	std z+2,R2
	.dbline 2211
; 				res = dir_seek(dj, 0);			/* Rewind dir */
	clr R18
	clr R19
	movw R16,R30
	xcall _dir_seek
	mov R10,R16
	mov R20,R10
	.dbline 2212
; 			}
L590:
	.dbline 2213
; 		}
L584:
	.dbline 2214
; 		if (res == FR_NO_FILE) res = FR_NO_PATH;
	cpi R20,4
	brne L592
X362:
	.dbline 2214
	ldi R20,5
L592:
	.dbline 2215
; 	}
L582:
	.dbline 2217
; 
; 	LEAVE_FF(dj->fs, res);
	mov R16,R20
	.dbline -2
L581:
	.dbline 0 ; func end
	adiw R28,13
	xcall pop_xgsetF00C
	adiw R28,2
	ret
	.dbsym l sfn 1 A[12:12]c
	.dbsym r dir 10 pc
	.dbsym r res 20 c
	.dbsym l path 19 pkc
	.dbsym r dj 22 pS[_DIR_]
	.dbend
	.dbfunc e f_readdir _f_readdir fc
;            sfn -> y+0
;            res -> R20
;            fno -> R10,R11
;             dj -> R22,R23
	.even
_f_readdir::
	xcall push_xgsetF03C
	movw R10,R18
	movw R22,R16
	sbiw R28,12
	.dbline -1
	.dbline 2231
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Read Directory Entry in Sequense                                      */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_readdir (
; 	DIR *dj,			/* Pointer to the open directory object */
; 	FILINFO *fno		/* Pointer to file information to return */
; )
; {
	.dbline 2236
; 	FRESULT res;
; 	NAMEBUF(sfn, lfn);
; 
; 
; 	res = validate(dj->fs, dj->id);			/* Check validity of the object */
	movw R30,R22
	ldd R18,z+2
	ldd R19,z+3
	ldd R16,z+0
	ldd R17,z+1
	xcall _validate
	mov R20,R16
	.dbline 2237
; 	if (res == FR_OK) {
	tst R16
	breq X371
	xjmp L595
X371:
X366:
	.dbline 2237
	.dbline 2238
; 		INITBUF((*dj), sfn, lfn);
	movw R24,R28
	movw R30,R22
	std z+21,R25
	std z+20,R24
	.dbline 2239
; 		if (!fno) {
	tst R10
	brne L597
	tst R11
	brne L597
X367:
	.dbline 2239
	.dbline 2240
; 			res = dir_seek(dj, 0);
	clr R18
	clr R19
	movw R16,R30
	xcall _dir_seek
	mov R20,R16
	.dbline 2241
; 		} else {
	xjmp L598
L597:
	.dbline 2241
	.dbline 2242
; 			res = dir_read(dj);
	movw R16,R22
	xcall _dir_read
	mov R12,R16
	mov R20,R12
	.dbline 2243
; 			if (res == FR_NO_FILE) {
	cpi R16,4
	brne L599
X368:
	.dbline 2243
	.dbline 2244
; 				dj->sect = 0;
	ldi R24,0
	ldi R25,0
	ldi R26,0
	ldi R27,0
	movw R30,R22
	std z+14,R24
	std z+15,R25
	std z+16,R26
	std z+17,R27
	.dbline 2245
; 				res = FR_OK;
	clr R20
	.dbline 2246
; 			}
L599:
	.dbline 2247
; 			if (res == FR_OK) {				/* A valid entry is found */
	tst R20
	brne L601
X369:
	.dbline 2247
	.dbline 2248
; 				get_fileinfo(dj, fno);		/* Get the object information */
	movw R18,R10
	movw R16,R22
	xcall _get_fileinfo
	.dbline 2249
; 				res = dir_next(dj, FALSE);	/* Increment index for next */
	clr R18
	movw R16,R22
	xcall _dir_next
	mov R10,R16
	mov R20,R10
	.dbline 2250
; 				if (res == FR_NO_FILE) {
	cpi R16,4
	brne L603
X370:
	.dbline 2250
	.dbline 2251
; 					dj->sect = 0;
	ldi R24,0
	ldi R25,0
	ldi R26,0
	ldi R27,0
	movw R30,R22
	std z+14,R24
	std z+15,R25
	std z+16,R26
	std z+17,R27
	.dbline 2252
; 					res = FR_OK;
	clr R20
	.dbline 2253
; 				}
L603:
	.dbline 2254
; 			}
L601:
	.dbline 2255
; 		}
L598:
	.dbline 2256
; 	}
L595:
	.dbline 2258
; 
; 	LEAVE_FF(dj->fs, res);
	mov R16,R20
	.dbline -2
L594:
	.dbline 0 ; func end
	adiw R28,12
	xjmp pop_xgsetF03C
	.dbsym l sfn 0 A[12:12]c
	.dbsym r res 20 c
	.dbsym r fno 10 pS[_FILINFO_]
	.dbsym r dj 22 pS[_DIR_]
	.dbend
	.dbfunc e f_stat _f_stat fc
;            sfn -> y+23
;             dj -> y+1
;            res -> R20
;            fno -> y+39
;           path -> y+37
	.even
_f_stat::
	xcall push_arg4
	st -y,R20
	st -y,R21
	sbiw R28,35
	.dbline -1
	.dbline 2272
; }
; 
; 
; 
; #if _FS_MINIMIZE == 0
; /*-----------------------------------------------------------------------*/
; /* Get File Status                                                       */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_stat (
; 	const XCHAR *path,	/* Pointer to the file path */
; 	FILINFO *fno		/* Pointer to file information to return */
; )
; {
	.dbline 2278
; 	FRESULT res;
; 	DIR dj;
; 	NAMEBUF(sfn, lfn);
; 
; 
; 	res = auto_mount(&path, &dj.fs, 0);
	clr R2
	std y+0,R2
	movw R18,R28
	subi R18,255  ; offset = 1
	sbci R19,255
	movw R16,R28
	subi R16,219  ; offset = 37
	sbci R17,255
	xcall _auto_mount
	mov R20,R16
	.dbline 2279
; 	if (res == FR_OK) {
	tst R16
	brne L606
X372:
	.dbline 2279
	.dbline 2280
; 		INITBUF(dj, sfn, lfn);
	movw R24,R28
	adiw R24,23
	std y+22,R25
	std y+21,R24
	.dbline 2281
; 		res = follow_path(&dj, path);	/* Follow the file path */
	ldd R18,y+37
	ldd R19,y+38
	movw R16,R28
	subi R16,255  ; offset = 1
	sbci R17,255
	xcall _follow_path
	mov R20,R16
	.dbline 2282
; 		if (res == FR_OK) {				/* Follwo completed */
	tst R16
	brne L609
X373:
	.dbline 2282
	.dbline 2283
; 			if (dj.dir)	/* Found an object */
	ldd R2,y+19
	ldd R3,y+20
	tst R2
	brne X374
	tst R3
	breq L611
X374:
	.dbline 2284
; 				get_fileinfo(&dj, fno);
	ldd R18,y+39
	ldd R19,y+40
	movw R16,R28
	subi R16,255  ; offset = 1
	sbci R17,255
	xcall _get_fileinfo
	xjmp L612
L611:
	.dbline 2286
; 			else		/* It is root dir */
; 				res = FR_INVALID_NAME;
	ldi R20,6
L612:
	.dbline 2287
; 		}
L609:
	.dbline 2288
; 	}
L606:
	.dbline 2290
; 
; 	LEAVE_FF(dj.fs, res);
	mov R16,R20
	.dbline -2
L605:
	.dbline 0 ; func end
	adiw R28,35
	ld R21,y+
	ld R20,y+
	adiw R28,4
	ret
	.dbsym l sfn 23 A[12:12]c
	.dbsym l dj 1 S[_DIR_]
	.dbsym r res 20 c
	.dbsym l fno 39 pS[_FILINFO_]
	.dbsym l path 37 pkc
	.dbend
	.dbfunc e f_getfree _f_getfree fc
;           sect -> y+14
;            fat -> y+23
;              n -> y+10
;            res -> y+22
;              i -> R12,R13
;           clst -> y+6
;           stat -> y+2
;              p -> R10,R11
;          fatfs -> y+38
;          nclst -> y+36
;           path -> y+34
	.even
_f_getfree::
	xcall push_arg4
	xcall push_xgsetF0FC
	sbiw R28,24
	.dbline -1
	.dbline 2305
; }
; 
; 
; 
; #if !_FS_READONLY
; /*-----------------------------------------------------------------------*/
; /* Get Number of Free Clusters                                           */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_getfree (
; 	const XCHAR *path,	/* Pointer to the logical drive number (root dir) */
; 	DWORD *nclst,		/* Pointer to the variable to return number of free clusters */
; 	FATFS **fatfs		/* Pointer to pointer to corresponding file system object to return */
; )
; {
	.dbline 2313
; 	FRESULT res;
; 	DWORD n, clst, sect, stat;
; 	UINT i;
; 	BYTE fat, *p;
; 
; 
; 	/* Get drive number */
; 	res = auto_mount(&path, fatfs, 0);
	clr R2
	std y+0,R2
	ldd R18,y+38
	ldd R19,y+39
	movw R16,R28
	subi R16,222  ; offset = 34
	sbci R17,255
	xcall _auto_mount
	std y+22,R16
	.dbline 2314
; 	if (res != FR_OK) LEAVE_FF(*fatfs, res);
	mov R0,R16
	tst R16
	breq L615
X375:
	.dbline 2314
	xjmp L614
L615:
	.dbline 2317
; 
; 	/* If number of free cluster is valid, return it without cluster scan. */
; 	if ((*fatfs)->free_clust <= (*fatfs)->max_clust - 2) {
	ldd R30,y+38
	ldd R31,y+39
	ldd R6,z+0
	ldd R7,z+1
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R6
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	ldd R6,z+14
	ldd R7,z+15
	ldd R8,z+16
	ldd R9,z+17
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brlo L617
X376:
	.dbline 2317
	.dbline 2318
; 		*nclst = (*fatfs)->free_clust;
	ldd R30,y+38
	ldd R31,y+39
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,14
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R30,y+36
	ldd R31,y+37
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 2319
; 		LEAVE_FF(*fatfs, FR_OK);
	clr R16
	xjmp L614
L617:
	.dbline 2323
; 	}
; 
; 	/* Get number of free clusters */
; 	fat = (*fatfs)->fs_type;
	ldd R30,y+38
	ldd R31,y+39
	ldd R26,z+0
	ldd R27,z+1
	ld R2,x
	std y+23,R2
	.dbline 2324
; 	n = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+10,R20
	std y+11,R21
	std y+12,R22
	std y+13,R23
	.dbline 2325
; 	if (fat == FS_FAT12) {
	ldd R24,y+23
	cpi R24,1
	breq X389
	xjmp L619
X389:
X377:
	.dbline 2325
	.dbline 2326
; 		clst = 2;
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+6,R20
	std y+7,R21
	std y+8,R22
	std y+9,R23
L621:
	.dbline 2327
; 		do {
	.dbline 2328
; 			stat = get_fat(*fatfs, clst);
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R30,y+38
	ldd R31,y+39
	ldd R16,z+0
	ldd R17,z+1
	xcall _get_fat
	std y+2,R16
	std y+3,R17
	std y+4,R18
	std y+5,R19
	.dbline 2329
; 			if (stat == 0xFFFFFFFF) LEAVE_FF(*fatfs, FR_DISK_ERR);
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L624
X378:
	.dbline 2329
	ldi R16,1
	xjmp L614
L624:
	.dbline 2330
; 			if (stat == 1) LEAVE_FF(*fatfs, FR_INT_ERR);
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L626
X379:
	.dbline 2330
	ldi R16,2
	xjmp L614
L626:
	.dbline 2331
; 			if (stat == 0) n++;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+2
	ldd R3,y+3
	ldd R4,y+4
	ldd R5,y+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L628
X380:
	.dbline 2331
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+10,R2
	std y+11,R3
	std y+12,R4
	std y+13,R5
L628:
	.dbline 2332
; 		} while (++clst < (*fatfs)->max_clust);
L622:
	.dbline 2332
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+18,R2
	std y+19,R3
	std y+20,R4
	std y+21,R5
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	ldd R30,y+38
	ldd R31,y+39
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R6,y+18
	ldd R7,y+19
	ldd R8,y+20
	ldd R9,y+21
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh X390
	xjmp L621
X390:
X381:
	.dbline 2333
; 	} else {
	xjmp L620
L619:
	.dbline 2333
	.dbline 2334
; 		clst = (*fatfs)->max_clust;
	ldd R30,y+38
	ldd R31,y+39
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	.dbline 2335
; 		sect = (*fatfs)->fatbase;
	ldd R30,y+38
	ldd R31,y+39
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,30
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	std y+14,R2
	std y+15,R3
	std y+16,R4
	std y+17,R5
	.dbline 2336
; 		i = 0; p = 0;
	clr R12
	clr R13
	.dbline 2336
	clr R10
	clr R11
L630:
	.dbline 2337
; 		do {
	.dbline 2338
; 			if (!i) {
	tst R12
	breq X391
	xjmp L633
X391:
	tst R13
	breq X392
	xjmp L633
X392:
X382:
	.dbline 2338
	.dbline 2339
; 				res = move_window(*fatfs, sect++);
	ldd R2,y+14
	ldd R3,y+15
	ldd R4,y+16
	ldd R5,y+17
	std y+18,R2
	std y+19,R3
	std y+20,R4
	std y+21,R5
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+14,R2
	std y+15,R3
	std y+16,R4
	std y+17,R5
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R30,y+38
	ldd R31,y+39
	ldd R16,z+0
	ldd R17,z+1
	xcall _move_window
	mov R14,R16
	std y+22,R14
	.dbline 2340
; 				if (res != FR_OK)
	mov R0,R14
	tst R16
	breq L635
X383:
	.dbline 2341
; 					LEAVE_FF(*fatfs, res);
	xjmp L614
L635:
	.dbline 2342
; 				p = (*fatfs)->win;
	ldd R30,y+38
	ldd R31,y+39
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,46
	movw R10,R24
	.dbline 2343
; 				i = SS(*fatfs);
	ldi R24,512
	ldi R25,2
	movw R12,R24
	.dbline 2344
; 			}
L633:
	.dbline 2345
; 			if (fat == FS_FAT16) {
	ldd R24,y+23
	cpi R24,2
	brne L637
X384:
	.dbline 2345
	.dbline 2346
; 				if (LD_WORD(p) == 0) n++;
	movw R30,R10
	ldd R2,z+0
	clr R3
	ldd R4,z+1
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	tst R4
	brne L639
	tst R5
	brne L639
X385:
	.dbline 2346
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+10,R2
	std y+11,R3
	std y+12,R4
	std y+13,R5
L639:
	.dbline 2347
; 				p += 2; i -= 2;
	movw R24,R10
	adiw R24,2
	movw R10,R24
	.dbline 2347
	movw R24,R12
	sbiw R24,2
	movw R12,R24
	.dbline 2348
; 			} else {
	xjmp L638
L637:
	.dbline 2348
	.dbline 2349
; 				if (LD_DWORD(p) == 0) n++;
	ldi R24,24
	ldi R25,0
	movw R30,R10
	ldd R16,z+3
	clr R17
	clr R18
	clr R19
	st -y,R24
	xcall lsl32
	movw R2,R16
	movw R4,R18
	movw R30,R10
	ldd R6,z+2
	clr R7
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+1
	clr R7
	mov R7,R6
	clr R6
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldd R6,z+0
	clr R7
	clr R8
	clr R9
	or R2,R6
	or R3,R7
	or R4,R8
	or R5,R9
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L641
X386:
	.dbline 2349
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+10,R2
	std y+11,R3
	std y+12,R4
	std y+13,R5
L641:
	.dbline 2350
; 				p += 4; i -= 4;
	movw R24,R10
	adiw R24,4
	movw R10,R24
	.dbline 2350
	movw R24,R12
	sbiw R24,4
	movw R12,R24
	.dbline 2351
; 			}
L638:
	.dbline 2352
; 		} while (--clst);
L631:
	.dbline 2352
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	std y+18,R2
	std y+19,R3
	std y+20,R4
	std y+21,R5
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+18
	ldd R3,y+19
	ldd R4,y+20
	ldd R5,y+21
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq X393
	xjmp L630
X393:
X387:
	.dbline 2353
; 	}
L620:
	.dbline 2354
; 	(*fatfs)->free_clust = n;
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	ldd R30,y+38
	ldd R31,y+39
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,14
	st x+,R2
	st x+,R3
	st x+,R4
	st x,R5
	.dbline 2355
; 	if (fat == FS_FAT32) (*fatfs)->fsi_flag = 1;
	ldd R24,y+23
	cpi R24,3
	brne L643
X388:
	.dbline 2355
	ldi R24,1
	ldd R30,y+38
	ldd R31,y+39
	push R26
	push R27
	ldd R26,z+0
	ldd R27,z+1
	movw R30,R26
	pop R27
	pop R26
	std z+9,R24
L643:
	.dbline 2356
; 	*nclst = n;
	ldd R2,y+10
	ldd R3,y+11
	ldd R4,y+12
	ldd R5,y+13
	ldd R30,y+36
	ldd R31,y+37
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 2358
; 
; 	LEAVE_FF(*fatfs, FR_OK);
	clr R16
	.dbline -2
L614:
	.dbline 0 ; func end
	adiw R28,24
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym l sect 14 l
	.dbsym l fat 23 c
	.dbsym l n 10 l
	.dbsym l res 22 c
	.dbsym r i 12 i
	.dbsym l clst 6 l
	.dbsym l stat 2 l
	.dbsym r p 10 pc
	.dbsym l fatfs 38 ppS[_FATFS_]
	.dbsym l nclst 36 pl
	.dbsym l path 34 pkc
	.dbend
	.dbfunc e f_truncate _f_truncate fc
;            ncl -> y+6
;            res -> R10
;             fp -> R12,R13
	.even
_f_truncate::
	xcall push_xgsetF0FC
	movw R12,R16
	sbiw R28,10
	.dbline -1
	.dbline 2371
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Truncate File                                                         */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_truncate (
; 	FIL *fp		/* Pointer to the file object */
; )
; {
	.dbline 2376
; 	FRESULT res;
; 	DWORD ncl;
; 
; 
; 	res = validate(fp->fs, fp->id);		/* Check validity of the object */
	movw R30,R12
	ldd R18,z+2
	ldd R19,z+3
	ldd R16,z+0
	ldd R17,z+1
	xcall _validate
	mov R10,R16
	.dbline 2377
; 	if (res != FR_OK) LEAVE_FF(fp->fs, res);
	tst R16
	breq L646
X394:
	.dbline 2377
	xjmp L645
L646:
	.dbline 2378
; 	if (fp->flag & FA__ERROR)			/* Check abort flag */
	movw R30,R12
	ldd R2,z+4
	sbrs R2,7
	rjmp L648
X395:
	.dbline 2379
; 		LEAVE_FF(fp->fs, FR_INT_ERR);
	ldi R16,2
	xjmp L645
L648:
	.dbline 2380
; 	if (!(fp->flag & FA_WRITE))			/* Check access mode */
	movw R30,R12
	ldd R2,z+4
	sbrc R2,1
	rjmp L650
X396:
	.dbline 2381
; 		LEAVE_FF(fp->fs, FR_DENIED);
	ldi R16,7
	xjmp L645
L650:
	.dbline 2383
; 
; 	if (fp->fsize > fp->fptr) {
	movw R30,R12
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	ldd R6,z+10
	ldd R7,z+11
	ldd R8,z+12
	ldd R9,z+13
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brlo X405
	xjmp L652
X405:
X397:
	.dbline 2383
	.dbline 2384
; 		fp->fsize = fp->fptr;	/* Set file size to current R/W point */
	std z+10,R2
	std z+11,R3
	std z+12,R4
	std z+13,R5
	.dbline 2385
; 		fp->flag |= FA__WRITTEN;
	movw R24,R30
	adiw R24,4
	movw R30,R24
	ldd R24,z+0
	ori R24,32
	std z+0,R24
	.dbline 2386
; 		if (fp->fptr == 0) {	/* When set file size to zero, remove entire cluster chain */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R12
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L654
X398:
	.dbline 2386
	.dbline 2387
; 			res = remove_chain(fp->fs, fp->org_clust);
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _remove_chain
	mov R14,R16
	mov R10,R14
	.dbline 2388
; 			fp->org_clust = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R12
	std z+14,R20
	std z+15,R21
	std z+16,R22
	std z+17,R23
	.dbline 2389
; 		} else {				/* When truncate a part of the file, remove remaining clusters */
	xjmp L655
L654:
	.dbline 2389
	.dbline 2390
; 			ncl = get_fat(fp->fs, fp->curr_clust);
	movw R30,R12
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _get_fat
	std y+6,R16
	std y+7,R17
	std y+8,R18
	std y+9,R19
	.dbline 2391
; 			res = FR_OK;
	clr R10
	.dbline 2392
; 			if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR;
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L656
X399:
	.dbline 2392
	clr R10
	inc R10
L656:
	.dbline 2393
; 			if (ncl == 1) res = FR_INT_ERR;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L658
X400:
	.dbline 2393
	ldi R24,2
	mov R10,R24
L658:
	.dbline 2394
; 			if (res == FR_OK && ncl < fp->fs->max_clust) {
	tst R10
	breq X406
	xjmp L660
X406:
X401:
	movw R30,R12
	ldd R26,z+0
	ldd R27,z+1
	adiw R26,26
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	ldd R6,y+6
	ldd R7,y+7
	ldd R8,y+8
	ldd R9,y+9
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brsh L660
X402:
	.dbline 2394
	.dbline 2395
; 				res = put_fat(fp->fs, fp->curr_clust, 0x0FFFFFFF);
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,15
	std y+2,R20
	std y+3,R21
	std y+4,R22
	std y+5,R23
	ldd R2,z+18
	ldd R3,z+19
	ldd R4,z+20
	ldd R5,z+21
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,z+0
	ldd R17,z+1
	xcall _put_fat
	mov R14,R16
	mov R10,R14
	.dbline 2396
; 				if (res == FR_OK) res = remove_chain(fp->fs, ncl);
	tst R16
	brne L662
X403:
	.dbline 2396
	ldd R2,y+6
	ldd R3,y+7
	ldd R4,y+8
	ldd R5,y+9
	std y+0,R4
	std y+1,R5
	movw R18,R2
	movw R30,R12
	ldd R16,z+0
	ldd R17,z+1
	xcall _remove_chain
	mov R14,R16
	mov R10,R14
L662:
	.dbline 2397
; 			}
L660:
	.dbline 2398
; 		}
L655:
	.dbline 2399
; 	}
L652:
	.dbline 2400
; 	if (res != FR_OK) fp->flag |= FA__ERROR;
	tst R10
	breq L664
X404:
	.dbline 2400
	movw R24,R12
	adiw R24,4
	movw R12,R24
	movw R30,R24
	ldd R24,z+0
	ori R24,128
	std z+0,R24
L664:
	.dbline 2402
; 
; 	LEAVE_FF(fp->fs, res);
	mov R16,R10
	.dbline -2
L645:
	.dbline 0 ; func end
	adiw R28,10
	xjmp pop_xgsetF0FC
	.dbsym l ncl 6 l
	.dbsym r res 10 c
	.dbsym r fp 12 pS[_FIL_]
	.dbend
	.dbfunc e f_unlink _f_unlink fc
;            sfn -> y+50
;            sdj -> y+28
;          dclst -> y+24
;             dj -> y+2
;            dir -> R12,R13
;            res -> R10
;           path -> y+70
	.even
_f_unlink::
	st -y,r17
	st -y,r16
	xcall push_xgsetF03C
	sbiw R28,62
	.dbline -1
	.dbline 2415
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Delete a File or Directory                                            */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_unlink (
; 	const XCHAR *path		/* Pointer to the file or directory path */
; )
; {
	.dbline 2423
; 	FRESULT res;
; 	DIR dj, sdj;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir;
; 	DWORD dclst;
; 
; 
; 	res = auto_mount(&path, &dj.fs, 1);
	ldi R24,1
	std y+0,R24
	movw R18,R28
	subi R18,254  ; offset = 2
	sbci R19,255
	movw R16,R28
	subi R16,186  ; offset = 70
	sbci R17,255
	xcall _auto_mount
	mov R10,R16
	.dbline 2424
; 	if (res != FR_OK) LEAVE_FF(dj.fs, res);
	tst R16
	breq L667
X407:
	.dbline 2424
	xjmp L666
L667:
	.dbline 2426
; 
; 	INITBUF(dj, sfn, lfn);
	movw R24,R28
	adiw R24,50
	std y+23,R25
	std y+22,R24
	.dbline 2427
; 	res = follow_path(&dj, path);			/* Follow the file path */
	movw R30,R28
	subi R30,186  ; addi 70
	sbci R31,255
	ldd R18,z+0
	ldd R19,z+1
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _follow_path
	mov R10,R16
	.dbline 2428
; 	if (_FS_RPATH && res == FR_OK && (dj.fn[11] & NS_DOT))
	xjmp L670
L670:
	.dbline 2430
; 		res = FR_INVALID_NAME;
; 	if (res != FR_OK) LEAVE_FF(dj.fs, res); /* Follow failed */
	tst R10
	breq L673
X408:
	.dbline 2430
	mov R16,R10
	xjmp L666
L673:
	.dbline 2432
; 
; 	dir = dj.dir;
	ldd R12,y+20
	ldd R13,y+21
	.dbline 2433
; 	if (!dir)								/* Is it the root directory? */
	tst R12
	brne L676
	tst R13
	brne L676
X409:
	.dbline 2434
; 		LEAVE_FF(dj.fs, FR_INVALID_NAME);
	ldi R16,6
	xjmp L666
L676:
	.dbline 2435
; 	if (dir[DIR_Attr] & AM_RDO)				/* Is it a R/O object? */
	movw R30,R12
	ldd R2,z+11
	sbrs R2,0
	rjmp L678
X410:
	.dbline 2436
; 		LEAVE_FF(dj.fs, FR_DENIED);
	ldi R16,7
	xjmp L666
L678:
	.dbline 2437
; 	dclst = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO);
	movw R30,R12
	ldd R2,z+26
	clr R3
	ldd R4,z+27
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,z+20
	clr R7
	ldd R8,z+21
	clr R9
	mov R9,R8
	clr R8
	or R8,R6
	or R9,R7
	movw R6,R8
	clr R8
	clr R9
	movw R8,R6
	clr R6
	clr R7
	or R6,R2
	or R7,R3
	or R8,R4
	or R9,R5
	std y+24,R6
	std y+25,R7
	std y+26,R8
	std y+27,R9
	.dbline 2439
; 
; 	if (dir[DIR_Attr] & AM_DIR) {			/* It is a sub-directory */
	ldd R2,z+11
	sbrs R2,4
	rjmp L680
X411:
	.dbline 2439
	.dbline 2440
; 		if (dclst < 2) LEAVE_FF(dj.fs, FR_INT_ERR);
	ldi R20,2
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brsh L682
X412:
	.dbline 2440
	ldi R16,2
	xjmp L666
L682:
	.dbline 2441
; 		mem_cpy(&sdj, &dj, sizeof(DIR));		/* Check if the sub-dir is empty or not */
	ldi R24,22
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R28
	subi R18,254  ; offset = 2
	sbci R19,255
	movw R16,R28
	subi R16,228  ; offset = 28
	sbci R17,255
	xcall _mem_cpy
	.dbline 2442
; 		sdj.sclust = dclst;
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	std y+34,R2
	std y+35,R3
	std y+36,R4
	std y+37,R5
	.dbline 2443
; 		res = dir_seek(&sdj, 0);
	clr R18
	clr R19
	movw R16,R28
	subi R16,228  ; offset = 28
	sbci R17,255
	xcall _dir_seek
	mov R12,R16
	mov R10,R12
	.dbline 2444
; 		if (res != FR_OK) LEAVE_FF(dj.fs, res);
	tst R16
	breq L685
X413:
	.dbline 2444
	xjmp L666
L685:
	.dbline 2445
; 		res = dir_read(&sdj);
	movw R16,R28
	subi R16,228  ; offset = 28
	sbci R17,255
	xcall _dir_read
	mov R12,R16
	mov R10,R12
	.dbline 2446
; 		if (res == FR_OK) res = FR_DENIED;	/* Not empty sub-dir */
	tst R16
	brne L687
X414:
	.dbline 2446
	ldi R24,7
	mov R10,R24
L687:
	.dbline 2447
; 		if (res != FR_NO_FILE) LEAVE_FF(dj.fs, res);
	mov R24,R10
	cpi R24,4
	breq L689
X415:
	.dbline 2447
	mov R16,R24
	xjmp L666
L689:
	.dbline 2448
; 	}
L680:
	.dbline 2450
; 
; 	res = dir_remove(&dj);					/* Remove directory entry */
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _dir_remove
	mov R12,R16
	mov R10,R12
	.dbline 2451
; 	if (res == FR_OK) {
	tst R16
	brne L691
X416:
	.dbline 2451
	.dbline 2452
; 		if (dclst)
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L693
X417:
	.dbline 2453
; 			res = remove_chain(dj.fs, dclst);	/* Remove the cluster chain */
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+2
	ldd R17,y+3
	xcall _remove_chain
	mov R12,R16
	mov R10,R12
L693:
	.dbline 2454
; 		if (res == FR_OK) res = sync(dj.fs);
	tst R10
	brne L695
X418:
	.dbline 2454
	ldd R16,y+2
	ldd R17,y+3
	xcall _sync
	mov R12,R16
	mov R10,R12
L695:
	.dbline 2455
; 	}
L691:
	.dbline 2457
; 
; 	LEAVE_FF(dj.fs, res);
	mov R16,R10
	.dbline -2
L666:
	.dbline 0 ; func end
	adiw R28,62
	xcall pop_xgsetF03C
	adiw R28,2
	ret
	.dbsym l sfn 50 A[12:12]c
	.dbsym l sdj 28 S[_DIR_]
	.dbsym l dclst 24 l
	.dbsym l dj 2 S[_DIR_]
	.dbsym r dir 12 pc
	.dbsym r res 10 c
	.dbsym l path 70 pkc
	.dbend
	.dbfunc e f_mkdir _f_mkdir fc
;            sfn -> y+40
;          pclst -> y+36
;            tim -> y+32
;          dsect -> y+28
;          dclst -> y+24
;              n -> R14
;            dir -> R12,R13
;            res -> y+56
;             dj -> y+2
;           path -> y+67
	.even
_f_mkdir::
	st -y,r17
	st -y,r16
	xcall push_xgsetF0FC
	sbiw R28,57
	.dbline -1
	.dbline 2470
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Create a Directory                                                    */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_mkdir (
; 	const XCHAR *path		/* Pointer to the directory path */
; )
; {
	.dbline 2478
; 	FRESULT res;
; 	DIR dj;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir, n;
; 	DWORD dsect, dclst, pclst, tim;
; 
; 
; 	res = auto_mount(&path, &dj.fs, 1);
	ldi R24,1
	std y+0,R24
	movw R18,R28
	subi R18,254  ; offset = 2
	sbci R19,255
	movw R16,R28
	subi R16,189  ; offset = 67
	sbci R17,255
	xcall _auto_mount
	std y+56,R16
	.dbline 2479
; 	if (res != FR_OK) LEAVE_FF(dj.fs, res);
	mov R0,R16
	tst R16
	breq L698
X419:
	.dbline 2479
	xjmp L697
L698:
	.dbline 2481
; 
; 	INITBUF(dj, sfn, lfn);
	movw R24,R28
	adiw R24,40
	std y+23,R25
	std y+22,R24
	.dbline 2482
; 	res = follow_path(&dj, path);			/* Follow the file path */
	movw R30,R28
	subi R30,189  ; addi 67
	sbci R31,255
	ldd R18,z+0
	ldd R19,z+1
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _follow_path
	std y+56,R16
	.dbline 2483
; 	if (res == FR_OK) res = FR_EXIST;		/* Any file or directory is already existing */
	mov R0,R16
	tst R16
	brne L701
X420:
	.dbline 2483
	ldi R24,8
	std y+56,R24
L701:
	.dbline 2484
; 	if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[11] & NS_DOT))
	xjmp L703
L703:
	.dbline 2486
; 		res = FR_INVALID_NAME;
; 	if (res != FR_NO_FILE)					/* Any error occured */
	ldd R24,y+56
	cpi R24,4
	breq L706
X421:
	.dbline 2487
; 		LEAVE_FF(dj.fs, res);
	mov R16,R24
	xjmp L697
L706:
	.dbline 2489
; 
; 	dclst = create_chain(dj.fs, 0);			/* Allocate a new cluster for new directory table */
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldd R16,y+2
	ldd R17,y+3
	xcall _create_chain
	std y+24,R16
	std y+25,R17
	std y+26,R18
	std y+27,R19
	.dbline 2490
; 	res = FR_OK;
	clr R0
	std y+56,R0
	.dbline 2491
; 	if (dclst == 0) res = FR_DENIED;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L708
X422:
	.dbline 2491
	ldi R24,7
	std y+56,R24
L708:
	.dbline 2492
; 	if (dclst == 1) res = FR_INT_ERR;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L710
X423:
	.dbline 2492
	ldi R24,2
	std y+56,R24
L710:
	.dbline 2493
; 	if (dclst == 0xFFFFFFFF) res = FR_DISK_ERR;
	ldi R20,255
	ldi R21,255
	ldi R22,255
	ldi R23,255
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L712
X424:
	.dbline 2493
	clr R0
	inc R0
	std y+56,R0
L712:
	.dbline 2494
; 	if (res == FR_OK)
	ldd R0,y+56
	tst R0
	brne L714
X425:
	.dbline 2495
; 		res = move_window(dj.fs, 0);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldd R16,y+2
	ldd R17,y+3
	xcall _move_window
	mov R10,R16
	std y+56,R10
L714:
	.dbline 2496
; 	if (res != FR_OK) LEAVE_FF(dj.fs, res);
	ldd R0,y+56
	tst R0
	breq L716
X426:
	.dbline 2496
	mov R16,R0
	xjmp L697
L716:
	.dbline 2497
; 	dsect = clust2sect(dj.fs, dclst);
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+2
	ldd R17,y+3
	xcall _clust2sect
	std y+28,R16
	std y+29,R17
	std y+30,R18
	std y+31,R19
	.dbline 2499
; 
; 	dir = dj.fs->win;						/* Initialize the new directory table */
	ldd R24,y+2
	ldd R25,y+3
	adiw R24,46
	movw R12,R24
	.dbline 2500
; 	mem_set(dir, 0, SS(dj.fs));
	ldi R24,512
	ldi R25,2
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	movw R16,R12
	xcall _mem_set
	.dbline 2501
; 	mem_set(dir+DIR_Name, ' ', 8+3);		/* Create "." entry */
	ldi R24,11
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldi R18,32
	ldi R19,0
	movw R16,R12
	xcall _mem_set
	.dbline 2502
; 	dir[DIR_Name] = '.';
	ldi R24,46
	movw R30,R12
	std z+0,R24
	.dbline 2503
; 	dir[DIR_Attr] = AM_DIR;
	ldi R24,16
	std z+11,R24
	.dbline 2504
; 	tim = get_fattime();
	xcall _get_fattime
	std y+32,R16
	std y+33,R17
	std y+34,R18
	std y+35,R19
	.dbline 2505
; 	ST_DWORD(dir+DIR_WrtTime, tim);
	ldd R2,y+32
	ldd R3,y+33
	ldd R4,y+34
	ldd R5,y+35
	movw R30,R12
	std z+22,R2
	.dbline 2505
	mov R2,R3
	clr R3
	std z+23,R2
	.dbline 2505
	ldd R2,y+32
	ldd R3,y+33
	ldd R4,y+34
	ldd R5,y+35
	movw R2,R4
	clr R4
	clr R5
	std z+24,R2
	.dbline 2505
	ldi R24,24
	ldi R25,0
	ldd R16,y+32
	ldd R17,y+33
	ldd R18,y+34
	ldd R19,y+35
	st -y,R24
	xcall lsr32
	movw R30,R12
	std z+25,R16
	.dbline 2506
; 	ST_WORD(dir+DIR_FstClusLO, dclst);
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	std z+26,R2
	.dbline 2506
	mov R2,R3
	clr R3
	std z+27,R2
	.dbline 2507
; 	ST_WORD(dir+DIR_FstClusHI, dclst >> 16);
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	movw R2,R4
	clr R4
	clr R5
	std z+20,R2
	.dbline 2507
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	movw R2,R4
	mov R2,R3
	clr R3
	std z+21,R2
	.dbline 2508
; 	mem_cpy(dir+32, dir, 32); 			/* Create ".." entry */
	ldi R24,32
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R30
	movw R16,R30
	subi R16,224  ; offset = 32
	sbci R17,255
	xcall _mem_cpy
	.dbline 2509
; 	dir[33] = '.';
	ldi R24,46
	movw R30,R12
	std z+33,R24
	.dbline 2510
; 	pclst = dj.sclust;
	ldd R2,y+8
	ldd R3,y+9
	ldd R4,y+10
	ldd R5,y+11
	std y+36,R2
	std y+37,R3
	std y+38,R4
	std y+39,R5
	.dbline 2511
; 	if (dj.fs->fs_type == FS_FAT32 && pclst == dj.fs->dirbase)
	ldd R30,y+2
	ldd R31,y+3
	ldd R24,z+0
	cpi R24,3
	brne L719
X427:
	ldd R2,z+34
	ldd R3,z+35
	ldd R4,z+36
	ldd R5,z+37
	ldd R6,y+36
	ldd R7,y+37
	ldd R8,y+38
	ldd R9,y+39
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L719
X428:
	.dbline 2512
; 		pclst = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+36,R20
	std y+37,R21
	std y+38,R22
	std y+39,R23
L719:
	.dbline 2513
; 	ST_WORD(dir+32+DIR_FstClusLO, pclst);
	ldd R2,y+36
	ldd R3,y+37
	ldd R4,y+38
	ldd R5,y+39
	movw R30,R12
	std z+58,R2
	.dbline 2513
	mov R2,R3
	clr R3
	std z+59,R2
	.dbline 2514
; 	ST_WORD(dir+32+DIR_FstClusHI, pclst >> 16);
	ldd R2,y+36
	ldd R3,y+37
	ldd R4,y+38
	ldd R5,y+39
	movw R2,R4
	clr R4
	clr R5
	std z+52,R2
	.dbline 2514
	ldd R2,y+36
	ldd R3,y+37
	ldd R4,y+38
	ldd R5,y+39
	movw R2,R4
	mov R2,R3
	clr R3
	std z+53,R2
	.dbline 2515
; 	for (n = 0; n < dj.fs->csize; n++) {	/* Write dot entries and clear left sectors */
	clr R14
	xjmp L724
L721:
	.dbline 2515
	.dbline 2516
; 		dj.fs->winsect = dsect++;
	ldd R2,y+28
	ldd R3,y+29
	ldd R4,y+30
	ldd R5,y+31
	std y+52,R2
	std y+53,R3
	std y+54,R4
	std y+55,R5
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+52
	ldd R3,y+53
	ldd R4,y+54
	ldd R5,y+55
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	std y+28,R2
	std y+29,R3
	std y+30,R4
	std y+31,R5
	ldd R2,y+52
	ldd R3,y+53
	ldd R4,y+54
	ldd R5,y+55
	ldd R30,y+2
	ldd R31,y+3
	std z+42,R2
	std z+43,R3
	std z+44,R4
	std z+45,R5
	.dbline 2517
; 		dj.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+2
	ldd R31,y+3
	std z+4,R24
	.dbline 2518
; 		res = move_window(dj.fs, 0);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	movw R16,R30
	xcall _move_window
	mov R10,R16
	std y+56,R10
	.dbline 2519
; 		if (res) LEAVE_FF(dj.fs, res);
	mov R0,R10
	tst R16
	breq L725
X429:
	.dbline 2519
	xjmp L697
L725:
	.dbline 2520
; 		mem_set(dir, 0, SS(dj.fs));
	ldi R24,512
	ldi R25,2
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	movw R16,R12
	xcall _mem_set
	.dbline 2521
; 	}
L722:
	.dbline 2515
	inc R14
L724:
	.dbline 2515
	ldd R30,y+2
	ldd R31,y+3
	ldd R2,z+2
	cp R14,R2
	brsh X432
	xjmp L721
X432:
X430:
	.dbline 2523
; 
; 	res = dir_register(&dj);
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _dir_register
	mov R14,R16
	std y+56,R14
	.dbline 2524
; 	if (res != FR_OK) {
	mov R0,R14
	tst R16
	breq L727
X431:
	.dbline 2524
	.dbline 2525
; 		remove_chain(dj.fs, dclst);
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+2
	ldd R17,y+3
	xcall _remove_chain
	.dbline 2526
; 	} else {
	xjmp L728
L727:
	.dbline 2526
	.dbline 2527
; 		dir = dj.dir;
	ldd R12,y+20
	ldd R13,y+21
	.dbline 2528
; 		dir[DIR_Attr] = AM_DIR;					/* Attribute */
	ldi R24,16
	movw R30,R12
	std z+11,R24
	.dbline 2529
; 		ST_DWORD(dir+DIR_WrtTime, tim);			/* Crated time */
	ldd R2,y+32
	ldd R3,y+33
	ldd R4,y+34
	ldd R5,y+35
	std z+22,R2
	.dbline 2529
	mov R2,R3
	clr R3
	std z+23,R2
	.dbline 2529
	ldd R2,y+32
	ldd R3,y+33
	ldd R4,y+34
	ldd R5,y+35
	movw R2,R4
	clr R4
	clr R5
	std z+24,R2
	.dbline 2529
	ldi R24,24
	ldi R25,0
	ldd R16,y+32
	ldd R17,y+33
	ldd R18,y+34
	ldd R19,y+35
	st -y,R24
	xcall lsr32
	movw R30,R12
	std z+25,R16
	.dbline 2530
; 		ST_WORD(dir+DIR_FstClusLO, dclst);		/* Table start cluster */
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	std z+26,R2
	.dbline 2530
	mov R2,R3
	clr R3
	std z+27,R2
	.dbline 2531
; 		ST_WORD(dir+DIR_FstClusHI, dclst >> 16);
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	movw R2,R4
	clr R4
	clr R5
	std z+20,R2
	.dbline 2531
	ldd R2,y+24
	ldd R3,y+25
	ldd R4,y+26
	ldd R5,y+27
	movw R2,R4
	mov R2,R3
	clr R3
	std z+21,R2
	.dbline 2532
; 		dj.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+2
	ldd R31,y+3
	std z+4,R24
	.dbline 2533
; 		res = sync(dj.fs);
	movw R16,R30
	xcall _sync
	mov R12,R16
	std y+56,R12
	.dbline 2534
; 	}
L728:
	.dbline 2536
; 
; 	LEAVE_FF(dj.fs, res);
	ldd R16,y+56
	.dbline -2
L697:
	.dbline 0 ; func end
	adiw R28,57
	xcall pop_xgsetF0FC
	adiw R28,2
	ret
	.dbsym l sfn 40 A[12:12]c
	.dbsym l pclst 36 l
	.dbsym l tim 32 l
	.dbsym l dsect 28 l
	.dbsym l dclst 24 l
	.dbsym r n 14 c
	.dbsym r dir 12 pc
	.dbsym l res 56 c
	.dbsym l dj 2 S[_DIR_]
	.dbsym l path 67 pkc
	.dbend
	.dbfunc e f_chmod _f_chmod fc
;            sfn -> y+23
;            dir -> R22,R23
;             dj -> y+1
;            res -> R20
;           mask -> R10
;          value -> y+43
;           path -> y+41
	.even
_f_chmod::
	xcall push_arg4
	xcall push_xgsetF00C
	sbiw R28,35
	ldd R10,y+45
	.dbline -1
	.dbline 2551
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Change File Attribute                                                 */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_chmod (
; 	const XCHAR *path,	/* Pointer to the file path */
; 	BYTE value,			/* Attribute bits */
; 	BYTE mask			/* Attribute mask to change */
; )
; {
	.dbline 2558
; 	FRESULT res;
; 	DIR dj;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir;
; 
; 
; 	res = auto_mount(&path, &dj.fs, 1);
	ldi R24,1
	std y+0,R24
	movw R18,R28
	subi R18,255  ; offset = 1
	sbci R19,255
	movw R16,R28
	subi R16,215  ; offset = 41
	sbci R17,255
	xcall _auto_mount
	mov R20,R16
	.dbline 2559
; 	if (res == FR_OK) {
	tst R16
	breq X436
	xjmp L731
X436:
X433:
	.dbline 2559
	.dbline 2560
; 		INITBUF(dj, sfn, lfn);
	movw R24,R28
	adiw R24,23
	std y+22,R25
	std y+21,R24
	.dbline 2561
; 		res = follow_path(&dj, path);		/* Follow the file path */
	ldd R18,y+41
	ldd R19,y+42
	movw R16,R28
	subi R16,255  ; offset = 1
	sbci R17,255
	xcall _follow_path
	mov R20,R16
	.dbline 2562
; 		if (_FS_RPATH && res == FR_OK && (dj.fn[11] & NS_DOT))
	xjmp L734
L734:
	.dbline 2564
; 			res = FR_INVALID_NAME;
; 		if (res == FR_OK) {
	tst R20
	brne L737
X434:
	.dbline 2564
	.dbline 2565
; 			dir = dj.dir;
	ldd R22,y+19
	ldd R23,y+20
	.dbline 2566
; 			if (!dir) {						/* Is it a root directory? */
	cpi R22,0
	cpc R22,R23
	brne L740
X435:
	.dbline 2566
	.dbline 2567
; 				res = FR_INVALID_NAME;
	ldi R20,6
	.dbline 2568
; 			} else {						/* File or sub directory */
	xjmp L741
L740:
	.dbline 2568
	.dbline 2569
; 				mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC;	/* Valid attribute mask */
	mov R24,R10
	andi R24,39
	.dbline 2570
; 				dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask);	/* Apply attribute change */
	subi R22,245  ; offset = 11
	sbci R23,255
	mov R2,R24
	clr R3
	com R2
	com R3
	movw R30,R22
	ldd R3,z+0
	and R3,R2
	ldd R2,y+43
	and R2,R24
	or R2,R3
	std z+0,R2
	.dbline 2571
; 				dj.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+1
	ldd R31,y+2
	std z+4,R24
	.dbline 2572
; 				res = sync(dj.fs);
	movw R16,R30
	xcall _sync
	mov R10,R16
	mov R20,R10
	.dbline 2573
; 			}
L741:
	.dbline 2574
; 		}
L737:
	.dbline 2575
; 	}
L731:
	.dbline 2577
; 
; 	LEAVE_FF(dj.fs, res);
	mov R16,R20
	.dbline -2
L730:
	.dbline 0 ; func end
	adiw R28,35
	xcall pop_xgsetF00C
	adiw R28,4
	ret
	.dbsym l sfn 23 A[12:12]c
	.dbsym r dir 22 pc
	.dbsym l dj 1 S[_DIR_]
	.dbsym r res 20 c
	.dbsym r mask 10 c
	.dbsym l value 43 c
	.dbsym l path 41 pkc
	.dbend
	.dbfunc e f_utime _f_utime fc
;            sfn -> y+23
;            dir -> R22,R23
;             dj -> y+1
;            res -> R20
;            fno -> R10,R11
;           path -> y+41
	.even
_f_utime::
	xcall push_arg4
	xcall push_xgsetF00C
	movw R10,R18
	sbiw R28,35
	.dbline -1
	.dbline 2591
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Change Timestamp                                                      */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_utime (
; 	const XCHAR *path,	/* Pointer to the file/directory name */
; 	const FILINFO *fno	/* Pointer to the timestamp to be set */
; )
; {
	.dbline 2598
; 	FRESULT res;
; 	DIR dj;
; 	NAMEBUF(sfn, lfn);
; 	BYTE *dir;
; 
; 
; 	res = auto_mount(&path, &dj.fs, 1);
	ldi R24,1
	std y+0,R24
	movw R18,R28
	subi R18,255  ; offset = 1
	sbci R19,255
	movw R16,R28
	subi R16,215  ; offset = 41
	sbci R17,255
	xcall _auto_mount
	mov R20,R16
	.dbline 2599
; 	if (res == FR_OK) {
	tst R16
	breq X440
	xjmp L743
X440:
X437:
	.dbline 2599
	.dbline 2600
; 		INITBUF(dj, sfn, lfn);
	movw R24,R28
	adiw R24,23
	std y+22,R25
	std y+21,R24
	.dbline 2601
; 		res = follow_path(&dj, path);	/* Follow the file path */
	ldd R18,y+41
	ldd R19,y+42
	movw R16,R28
	subi R16,255  ; offset = 1
	sbci R17,255
	xcall _follow_path
	mov R20,R16
	.dbline 2602
; 		if (_FS_RPATH && res == FR_OK && (dj.fn[11] & NS_DOT))
	xjmp L746
L746:
	.dbline 2604
; 			res = FR_INVALID_NAME;
; 		if (res == FR_OK) {
	tst R20
	breq X441
	xjmp L749
X441:
X438:
	.dbline 2604
	.dbline 2605
; 			dir = dj.dir;
	ldd R22,y+19
	ldd R23,y+20
	.dbline 2606
; 			if (!dir) {				/* Root directory */
	cpi R22,0
	cpc R22,R23
	brne L752
X439:
	.dbline 2606
	.dbline 2607
; 				res = FR_INVALID_NAME;
	ldi R20,6
	.dbline 2608
; 			} else {				/* File or sub-directory */
	xjmp L753
L752:
	.dbline 2608
	.dbline 2609
; 				ST_WORD(dir+DIR_WrtTime, fno->ftime);
	movw R30,R10
	adiw R30,6
	lpm R2,Z+
	lpm R3,Z
	movw R30,R22
	std z+22,R2
	.dbline 2609
	movw R30,R10
	adiw R30,6
	lpm R2,Z+
	lpm R3,Z
	mov R2,R3
	clr R3
	movw R30,R22
	std z+23,R2
	.dbline 2610
; 				ST_WORD(dir+DIR_WrtDate, fno->fdate);
	movw R30,R10
	adiw R30,4
	lpm R2,Z+
	lpm R3,Z
	movw R30,R22
	std z+24,R2
	.dbline 2610
	movw R30,R10
	adiw R30,4
	lpm R2,Z+
	lpm R3,Z
	mov R2,R3
	clr R3
	movw R30,R22
	std z+25,R2
	.dbline 2611
; 				dj.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+1
	ldd R31,y+2
	std z+4,R24
	.dbline 2612
; 				res = sync(dj.fs);
	movw R16,R30
	xcall _sync
	mov R10,R16
	mov R20,R10
	.dbline 2613
; 			}
L753:
	.dbline 2614
; 		}
L749:
	.dbline 2615
; 	}
L743:
	.dbline 2617
; 
; 	LEAVE_FF(dj.fs, res);
	mov R16,R20
	.dbline -2
L742:
	.dbline 0 ; func end
	adiw R28,35
	xcall pop_xgsetF00C
	adiw R28,4
	ret
	.dbsym l sfn 23 A[12:12]c
	.dbsym r dir 22 pc
	.dbsym l dj 1 S[_DIR_]
	.dbsym r res 20 c
	.dbsym r fno 10 pkS[_FILINFO_]
	.dbsym l path 41 pkc
	.dbend
	.dbfunc e f_rename _f_rename fc
;             dw -> y+79
;            sfn -> y+67
;            buf -> y+46
;            dir -> R12,R13
;         dj_new -> y+24
;         dj_old -> y+2
;            res -> R10
;       path_new -> y+99
;       path_old -> y+97
	.even
_f_rename::
	xcall push_arg4
	xcall push_xgsetF0FC
	sbiw R28,63
	sbiw R28,24  ; offset = 87
	.dbline -1
	.dbline 2631
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Rename File/Directory                                                 */
; /*-----------------------------------------------------------------------*/
; 
; FRESULT f_rename (
; 	const XCHAR *path_old,	/* Pointer to the old name */
; 	const XCHAR *path_new	/* Pointer to the new name */
; )
; {
	.dbline 2639
; 	FRESULT res;
; 	DIR dj_old, dj_new;
; 	NAMEBUF(sfn, lfn);
; 	BYTE buf[21], *dir;
; 	DWORD dw;
; 
; 
; 	INITBUF(dj_old, sfn, lfn);
	movw R24,R28
	subi R24,189  ; offset = 67
	sbci R25,255
	std y+23,R25
	std y+22,R24
	.dbline 2640
; 	res = auto_mount(&path_old, &dj_old.fs, 1);
	ldi R24,1
	std y+0,R24
	movw R18,R28
	subi R18,254  ; offset = 2
	sbci R19,255
	movw R16,R28
	subi R16,159  ; offset = 97
	sbci R17,255
	xcall _auto_mount
	mov R10,R16
	.dbline 2641
; 	if (res == FR_OK) {
	tst R16
	brne L756
X442:
	.dbline 2641
	.dbline 2642
; 		dj_new.fs = dj_old.fs;
	ldd R2,y+2
	ldd R3,y+3
	std y+25,R3
	std y+24,R2
	.dbline 2643
; 		res = follow_path(&dj_old, path_old);	/* Check old object */
	movw R30,R28
	subi R30,159  ; addi 97
	sbci R31,255
	ldd R18,z+0
	ldd R19,z+1
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _follow_path
	mov R10,R16
	.dbline 2644
; 		if (_FS_RPATH && res == FR_OK && (dj_old.fn[11] & NS_DOT))
	xjmp L758
L758:
	.dbline 2646
; 			res = FR_INVALID_NAME;
; 	}
L756:
	.dbline 2647
; 	if (res != FR_OK) LEAVE_FF(dj_old.fs, res);	/* The old object is not found */
	tst R10
	breq L761
X443:
	.dbline 2647
	mov R16,R10
	xjmp L754
L761:
	.dbline 2649
; 
; 	if (!dj_old.dir) LEAVE_FF(dj_old.fs, FR_NO_FILE);	/* Is root dir? */
	ldd R2,y+20
	ldd R3,y+21
	tst R2
	brne L763
	tst R3
	brne L763
X444:
	.dbline 2649
	ldi R16,4
	xjmp L754
L763:
	.dbline 2650
; 	mem_cpy(buf, dj_old.dir+DIR_Attr, 21);		/* Save the object information */
	ldi R24,21
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldd R18,y+20
	ldd R19,y+21
	subi R18,245  ; offset = 11
	sbci R19,255
	movw R16,R28
	subi R16,210  ; offset = 46
	sbci R17,255
	xcall _mem_cpy
	.dbline 2652
; 
; 	mem_cpy(&dj_new, &dj_old, sizeof(DIR));
	ldi R24,22
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R28
	subi R18,254  ; offset = 2
	sbci R19,255
	movw R16,R28
	subi R16,232  ; offset = 24
	sbci R17,255
	xcall _mem_cpy
	.dbline 2653
; 	res = follow_path(&dj_new, path_new);		/* Check new object */
	movw R30,R28
	subi R30,157  ; addi 99
	sbci R31,255
	ldd R18,z+0
	ldd R19,z+1
	movw R16,R28
	subi R16,232  ; offset = 24
	sbci R17,255
	xcall _follow_path
	mov R12,R16
	mov R10,R12
	.dbline 2654
; 	if (res == FR_OK) res = FR_EXIST;			/* The new object name is already existing */
	tst R16
	brne L767
X445:
	.dbline 2654
	ldi R24,8
	mov R10,R24
L767:
	.dbline 2655
; 	if (res == FR_NO_FILE) { 					/* Is it a valid path and no name collision? */
	mov R24,R10
	cpi R24,4
	breq X456
	xjmp L769
X456:
X446:
	.dbline 2655
	.dbline 2656
; 		res = dir_register(&dj_new);			/* Register the new object */
	movw R16,R28
	subi R16,232  ; offset = 24
	sbci R17,255
	xcall _dir_register
	mov R12,R16
	mov R10,R12
	.dbline 2657
; 		if (res == FR_OK) {
	tst R16
	breq X457
	xjmp L771
X457:
X447:
	.dbline 2657
	.dbline 2658
; 			dir = dj_new.dir;					/* Copy object information into new entry */
	ldd R12,y+42
	ldd R13,y+43
	.dbline 2659
; 			mem_cpy(dir+13, buf+2, 19);
	ldi R24,19
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R28
	subi R18,208  ; offset = 48
	sbci R19,255
	movw R16,R12
	subi R16,243  ; offset = 13
	sbci R17,255
	xcall _mem_cpy
	.dbline 2660
; 			dir[DIR_Attr] = buf[0] | AM_ARC;
	ldd R24,y+46
	ori R24,32
	movw R30,R12
	std z+11,R24
	.dbline 2661
; 			dj_old.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+2
	ldd R31,y+3
	std z+4,R24
	.dbline 2662
; 			if (dir[DIR_Attr] & AM_DIR) {		/* Update .. entry in the directory if needed */
	movw R30,R12
	ldd R2,z+11
	sbrs R2,4
	rjmp L775
X448:
	.dbline 2662
	.dbline 2663
; 				dw = clust2sect(dj_new.fs, (DWORD)LD_WORD(dir+DIR_FstClusHI) | LD_WORD(dir+DIR_FstClusLO));
	ldd R2,z+26
	clr R3
	ldd R4,z+27
	clr R5
	mov R5,R4
	clr R4
	or R4,R2
	or R5,R3
	movw R2,R4
	clr R4
	clr R5
	ldd R6,z+20
	clr R7
	ldd R8,z+21
	clr R9
	mov R9,R8
	clr R8
	or R8,R6
	or R9,R7
	movw R6,R8
	clr R8
	clr R9
	or R6,R2
	or R7,R3
	or R8,R4
	or R9,R5
	std y+0,R8
	std y+1,R9
	movw R18,R6
	ldd R16,y+24
	ldd R17,y+25
	xcall _clust2sect
	movw R30,R28
	subi R30,177  ; addi 79
	sbci R31,255
	std z+0,R16
	std z+1,R17
	std z+2,R18
	std z+3,R19
	.dbline 2664
; 				if (!dw) {
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	subi R30,177  ; addi 79
	sbci R31,255
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L777
X449:
	.dbline 2664
	.dbline 2665
; 					res = FR_INT_ERR;
	ldi R24,2
	mov R10,R24
	.dbline 2666
; 				} else {
	xjmp L778
L777:
	.dbline 2666
	.dbline 2667
; 					res = move_window(dj_new.fs, dw);
	movw R30,R28
	subi R30,177  ; addi 79
	sbci R31,255
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldd R16,y+24
	ldd R17,y+25
	xcall _move_window
	mov R14,R16
	mov R10,R14
	.dbline 2668
; 					dir = dj_new.fs->win+32;
	ldd R24,y+24
	ldd R25,y+25
	subi R24,178  ; offset = 78
	sbci R25,255
	movw R12,R24
	.dbline 2669
; 					if (res == FR_OK && dir[1] == '.') {
	tst R16
	breq X458
	xjmp L779
X458:
X450:
	movw R30,R24
	ldd R24,z+1
	cpi R24,46
	breq X459
	xjmp L779
X459:
X451:
	.dbline 2669
	.dbline 2670
; 						dw = (dj_new.fs->fs_type == FS_FAT32 && dj_new.sclust == dj_new.fs->dirbase) ? 0 : dj_new.sclust;
	ldd R30,y+24
	ldd R31,y+25
	ldd R24,z+0
	cpi R24,3
	brne L783
X452:
	ldd R2,z+34
	ldd R3,z+35
	ldd R4,z+36
	ldd R5,z+37
	ldd R6,y+30
	ldd R7,y+31
	ldd R8,y+32
	ldd R9,y+33
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L783
X453:
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	subi R30,173  ; addi 83
	sbci R31,255
	std z+0,R20
	std z+1,R21
	std z+2,R22
	std z+3,R23
	xjmp L784
L783:
	ldd R2,y+30
	ldd R3,y+31
	ldd R4,y+32
	ldd R5,y+33
	movw R30,R28
	subi R30,173  ; addi 83
	sbci R31,255
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
L784:
	movw R30,R28
	subi R30,173  ; addi 83
	sbci R31,255
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	movw R30,R28
	subi R30,177  ; addi 79
	sbci R31,255
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 2671
; 						ST_WORD(dir+DIR_FstClusLO, dw);
	movw R30,R28
	subi R30,177  ; addi 79
	sbci R31,255
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	movw R30,R12
	std z+26,R2
	.dbline 2671
	mov R2,R3
	clr R3
	std z+27,R2
	.dbline 2672
; 						ST_WORD(dir+DIR_FstClusHI, dw >> 16);
	movw R26,R28
	subi R26,177  ; addi 79
	sbci R27,255
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	movw R2,R4
	clr R4
	clr R5
	std z+20,R2
	.dbline 2672
	movw R26,R28
	subi R26,177  ; addi 79
	sbci R27,255
	ld R2,x+
	ld R3,x+
	ld R4,x+
	ld R5,x
	movw R2,R4
	mov R2,R3
	clr R3
	std z+21,R2
	.dbline 2673
; 						dj_new.fs->wflag = 1;
	ldi R24,1
	ldd R30,y+24
	ldd R31,y+25
	std z+4,R24
	.dbline 2674
; 					}
L779:
	.dbline 2675
; 				}
L778:
	.dbline 2676
; 			}
L775:
	.dbline 2677
; 			if (res == FR_OK) {
	tst R10
	brne L785
X454:
	.dbline 2677
	.dbline 2678
; 				res = dir_remove(&dj_old);			/* Remove old entry */
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _dir_remove
	mov R12,R16
	mov R10,R12
	.dbline 2679
; 				if (res == FR_OK)
	tst R16
	brne L787
X455:
	.dbline 2680
; 					res = sync(dj_old.fs);
	ldd R16,y+2
	ldd R17,y+3
	xcall _sync
	mov R12,R16
	mov R10,R12
L787:
	.dbline 2681
; 			}
L785:
	.dbline 2682
; 		}
L771:
	.dbline 2683
; 	}
L769:
	.dbline 2685
; 
; 	LEAVE_FF(dj_old.fs, res);
	mov R16,R10
	.dbline -2
L754:
	.dbline 0 ; func end
	adiw R28,63
	adiw R28,24  ; offset = 87
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym l dw 79 l
	.dbsym l sfn 67 A[12:12]c
	.dbsym l buf 46 A[21:21]c
	.dbsym r dir 12 pc
	.dbsym l dj_new 24 S[_DIR_]
	.dbsym l dj_old 2 S[_DIR_]
	.dbsym r res 10 c
	.dbsym l path_new 99 pkc
	.dbsym l path_old 97 pkc
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\ff.c
_Fsid:
	.blkb 2
	.dbsym s Fsid _Fsid s
_FatFs:
	.blkb 2
	.dbsym s FatFs _FatFs A[2:1]pS[_FATFS_]
	.area data(ram, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\ff.c
L268:
	.blkb 11
	.area idata
	.byte 32,34,42,43,44,91,61,93,124,127,0
	.area data(ram, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\ff.c
; }
; 
; #endif /* !_FS_READONLY */
; #endif /* _FS_MINIMIZE == 0 */
; #endif /* _FS_MINIMIZE <= 1 */
; #endif /* _FS_MINIMIZE <= 2 */
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Forward data to the stream directly (Available on only _FS_TINY cfg)  */
; /*-----------------------------------------------------------------------*/
; #if _USE_FORWARD && _FS_TINY
; 
; FRESULT f_forward (
; 	FIL *fp, 						/* Pointer to the file object */
; 	UINT (*func)(const BYTE*,UINT),	/* Pointer to the streaming function */
; 	UINT btr,						/* Number of bytes to forward */
; 	UINT *bf						/* Pointer to number of bytes forwarded */
; )
; {
; 	FRESULT res;
; 	DWORD remain, clst, sect;
; 	UINT rcnt;
; 
; 
; 	*bf = 0;
; 
; 	res = validate(fp->fs, fp->id);					/* Check validity of the object */
; 	if (res != FR_OK) LEAVE_FF(fp->fs, res);
; 	if (fp->flag & FA__ERROR)						/* Check error flag */
; 		LEAVE_FF(fp->fs, FR_INT_ERR);
; 	if (!(fp->flag & FA_READ))						/* Check access mode */
; 		LEAVE_FF(fp->fs, FR_DENIED);
; 
; 	remain = fp->fsize - fp->fptr;
; 	if (btr > remain) btr = (UINT)remain;			/* Truncate btr by remaining bytes */
; 
; 	for ( ;  btr && (*func)(NULL, 0);				/* Repeat until all data transferred or stream becomes busy */
; 		fp->fptr += rcnt, *bf += rcnt, btr -= rcnt) {
; 		if ((fp->fptr % SS(fp->fs)) == 0) {			/* On the sector boundary? */
; 			if (fp->csect >= fp->fs->csize) {		/* On the cluster boundary? */
; 				clst = (fp->fptr == 0) ?			/* On the top of the file? */
; 					fp->org_clust : get_fat(fp->fs, fp->curr_clust);
; 				if (clst <= 1) ABORT(fp->fs, FR_INT_ERR);
; 				if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
; 				fp->curr_clust = clst;				/* Update current cluster */
; 				fp->csect = 0;						/* Reset sector address in the cluster */
; 			}
; 			fp->csect++;							/* Next sector address in the cluster */
; 		}
; 		sect = clust2sect(fp->fs, fp->curr_clust);	/* Get current data sector */
; 		if (!sect) ABORT(fp->fs, FR_INT_ERR);
; 		sect += fp->csect - 1;
; 		if (move_window(fp->fs, sect))				/* Move sector window */
; 			ABORT(fp->fs, FR_DISK_ERR);
; 		fp->dsect = sect;
; 		rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs));	/* Forward data from sector window */
; 		if (rcnt > btr) rcnt = btr;
; 		rcnt = (*func)(&fp->fs->win[(WORD)fp->fptr % SS(fp->fs)], rcnt);
; 		if (!rcnt) ABORT(fp->fs, FR_INT_ERR);
; 	}
; 
; 	LEAVE_FF(fp->fs, FR_OK);
; }
; #endif /* _USE_FORWARD */
; 
; 
; 
; #if _USE_MKFS && !_FS_READONLY
; /*-----------------------------------------------------------------------*/
; /* Create File System on the Drive                                       */
; /*-----------------------------------------------------------------------*/
; #define N_ROOTDIR	512			/* Multiple of 32 and <= 2048 */
; #define N_FATS		1			/* 1 or 2 */
; #define MAX_SECTOR	131072000UL	/* Maximum partition size */
; #define MIN_SECTOR	2000UL		/* Minimum partition size */
; 
; 
; FRESULT f_mkfs (
; 	BYTE drv,			/* Logical drive number */
; 	BYTE partition,		/* Partitioning rule 0:FDISK, 1:SFD */
; 	WORD allocsize		/* Allocation unit size [bytes] */
; )
; {
; 	static const DWORD sstbl[] = { 2048000, 1024000, 512000, 256000, 128000, 64000, 32000, 16000, 8000, 4000,   0 };
; 	static const WORD cstbl[] =  {   32768,   16384,   8192,   4096,   2048, 16384,  8192,  4096, 2048, 1024, 512 };
; 	BYTE fmt, m, *tbl;
; 	DWORD b_part, b_fat, b_dir, b_data;		/* Area offset (LBA) */
; 	DWORD n_part, n_rsv, n_fat, n_dir;		/* Area size */
; 	DWORD n_clst, d, n;
; 	WORD as;
; 	FATFS *fs;
; 	DSTATUS stat;
; 
; 
; 	/* Check validity of the parameters */
; 	if (drv >= _DRIVES) return FR_INVALID_DRIVE;
; 	if (partition >= 2) return FR_MKFS_ABORTED;
; 
; 	/* Check mounted drive and clear work area */
; 	fs = FatFs[drv];
; 	if (!fs) return FR_NOT_ENABLED;
; 	fs->fs_type = 0;
; 	drv = LD2PD(drv);
; 
; 	/* Get disk statics */
; 	stat = disk_initialize(drv);
; 	if (stat & STA_NOINIT) return FR_NOT_READY;
; 	if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
; #if _MAX_SS != 512						/* Get disk sector size */
; 	if (disk_ioctl(drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK
; 		|| SS(fs) > _MAX_SS)
; 		return FR_MKFS_ABORTED;
; #endif
; 	if (disk_ioctl(drv, GET_SECTOR_COUNT, &n_part) != RES_OK || n_part < MIN_SECTOR)
; 		return FR_MKFS_ABORTED;
; 	if (n_part > MAX_SECTOR) n_part = MAX_SECTOR;
; 	b_part = (!partition) ? 63 : 0;		/* Boot sector */
; 	n_part -= b_part;
; 	for (d = 512; d <= 32768U && d != allocsize; d <<= 1) ;	/* Check validity of the allocation unit size */
; 	if (d != allocsize) allocsize = 0;
; 	if (!allocsize) {					/* Auto selection of cluster size */
; 		d = n_part;
; 		for (as = SS(fs); as > 512U; as >>= 1) d >>= 1;
; 		for (n = 0; d < sstbl[n]; n++) ;
; 		allocsize = cstbl[n];
; 	}
; 	if (allocsize < SS(fs)) allocsize = SS(fs);
; 
; 	allocsize /= SS(fs);		/* Number of sectors per cluster */
; 
; 	/* Pre-compute number of clusters and FAT type */
; 	n_clst = n_part / allocsize;
; 	fmt = FS_FAT12;
; 	if (n_clst >= 0xFF5) fmt = FS_FAT16;
; 	if (n_clst >= 0xFFF5) fmt = FS_FAT32;
; 
; 	/* Determine offset and size of FAT structure */
; 	switch (fmt) {
; 	case FS_FAT12:
; 		n_fat = ((n_clst * 3 + 1) / 2 + 3 + SS(fs) - 1) / SS(fs);
; 		n_rsv = 1 + partition;
; 		n_dir = N_ROOTDIR * 32 / SS(fs);
; 		break;
; 	case FS_FAT16:
; 		n_fat = ((n_clst * 2) + 4 + SS(fs) - 1) / SS(fs);
; 		n_rsv = 1 + partition;
; 		n_dir = N_ROOTDIR * 32 / SS(fs);
; 		break;
; 	default:
; 		n_fat = ((n_clst * 4) + 8 + SS(fs) - 1) / SS(fs);
; 		n_rsv = 33 - partition;
; 		n_dir = 0;
; 	}
; 	b_fat = b_part + n_rsv;			/* FATs start sector */
; 	b_dir = b_fat + n_fat * N_FATS;	/* Directory start sector */
; 	b_data = b_dir + n_dir;			/* Data start sector */
; 
; 	/* Align data start sector to erase block boundary (for flash memory media) */
; 	if (disk_ioctl(drv, GET_BLOCK_SIZE, &n) != RES_OK) return FR_MKFS_ABORTED;
; 	n = (b_data + n - 1) & ~(n - 1);
; 	n_fat += (n - b_data) / N_FATS;
; 	/* b_dir and b_data are no longer used below */
; 
; 	/* Determine number of cluster and final check of validity of the FAT type */
; 	n_clst = (n_part - n_rsv - n_fat * N_FATS - n_dir) / allocsize;
; 	if (   (fmt == FS_FAT16 && n_clst < 0xFF5)
; 		|| (fmt == FS_FAT32 && n_clst < 0xFFF5))
; 		return FR_MKFS_ABORTED;
; 
; 	/* Create partition table if needed */
; 	if (!partition) {
; 		DWORD n_disk = b_part + n_part;
; 
; 		mem_set(fs->win, 0, SS(fs));
; 		tbl = fs->win+MBR_Table;
; 		ST_DWORD(tbl, 0x00010180);		/* Partition start in CHS */
; 		if (n_disk < 63UL * 255 * 1024) {	/* Partition end in CHS */
; 			n_disk = n_disk / 63 / 255;
; 			tbl[7] = (BYTE)n_disk;
; 			tbl[6] = (BYTE)((n_disk >> 2) | 63);
; 		} else {
; 			ST_WORD(&tbl[6], 0xFFFF);
; 		}
; 		tbl[5] = 254;
; 		if (fmt != FS_FAT32)			/* System ID */
; 			tbl[4] = (n_part < 0x10000) ? 0x04 : 0x06;
; 		else
; 			tbl[4] = 0x0c;
; 		ST_DWORD(tbl+8, 63);			/* Partition start in LBA */
; 		ST_DWORD(tbl+12, n_part);		/* Partition size in LBA */
; 		ST_WORD(tbl+64, 0xAA55);		/* Signature */
; 		if (disk_write(drv, fs->win, 0, 1) != RES_OK)
; 			return FR_DISK_ERR;
; 		partition = 0xF8;
; 	} else {
; 		partition = 0xF0;
; 	}
; 
; 	/* Create boot record */
; 	tbl = fs->win;								/* Clear buffer */
; 	mem_set(tbl, 0, SS(fs));
; 	ST_DWORD(tbl+BS_jmpBoot, 0x90FEEB);			/* Boot code (jmp $, nop) */
; 	ST_WORD(tbl+BPB_BytsPerSec, SS(fs));		/* Sector size */
; 	tbl[BPB_SecPerClus] = (BYTE)allocsize;		/* Sectors per cluster */
; 	ST_WORD(tbl+BPB_RsvdSecCnt, n_rsv);			/* Reserved sectors */
; 	tbl[BPB_NumFATs] = N_FATS;					/* Number of FATs */
; 	ST_WORD(tbl+BPB_RootEntCnt, SS(fs) / 32 * n_dir); /* Number of rootdir entries */
; 	if (n_part < 0x10000) {						/* Number of total sectors */
; 		ST_WORD(tbl+BPB_TotSec16, n_part);
; 	} else {
; 		ST_DWORD(tbl+BPB_TotSec32, n_part);
; 	}
; 	tbl[BPB_Media] = partition;					/* Media descripter */
; 	ST_WORD(tbl+BPB_SecPerTrk, 63);				/* Number of sectors per track */
; 	ST_WORD(tbl+BPB_NumHeads, 255);				/* Number of heads */
; 	ST_DWORD(tbl+BPB_HiddSec, b_part);			/* Hidden sectors */
; 	n = get_fattime();							/* Use current time as a VSN */
; 	if (fmt != FS_FAT32) {
; 		ST_DWORD(tbl+BS_VolID, n);				/* Volume serial number */
; 		ST_WORD(tbl+BPB_FATSz16, n_fat);		/* Number of secters per FAT */
; 		tbl[BS_DrvNum] = 0x80;					/* Drive number */
; 		tbl[BS_BootSig] = 0x29;					/* Extended boot signature */
; 		mem_cpy(tbl+BS_VolLab, "NO NAME    FAT     ", 19);	/* Volume lavel, FAT signature */
; 	} else {
; 		ST_DWORD(tbl+BS_VolID32, n);			/* Volume serial number */
; 		ST_DWORD(tbl+BPB_FATSz32, n_fat);		/* Number of secters per FAT */
; 		ST_DWORD(tbl+BPB_RootClus, 2);			/* Root directory cluster (2) */
; 		ST_WORD(tbl+BPB_FSInfo, 1);				/* FSInfo record offset (bs+1) */
; 		ST_WORD(tbl+BPB_BkBootSec, 6);			/* Backup boot record offset (bs+6) */
; 		tbl[BS_DrvNum32] = 0x80;				/* Drive number */
; 		tbl[BS_BootSig32] = 0x29;				/* Extended boot signature */
; 		mem_cpy(tbl+BS_VolLab32, "NO NAME    FAT32   ", 19);	/* Volume lavel, FAT signature */
; 	}
; 	ST_WORD(tbl+BS_55AA, 0xAA55);				/* Signature */
; 	if (SS(fs) > 512U) {
; 		ST_WORD(tbl+SS(fs)-2, 0xAA55);
; 	}
; 	if (disk_write(drv, tbl, b_part+0, 1) != RES_OK)
; 		return FR_DISK_ERR;
; 	if (fmt == FS_FAT32)
; 		disk_write(drv, tbl, b_part+6, 1);
; 
; 	/* Initialize FAT area */
; 	for (m = 0; m < N_FATS; m++) {
; 		mem_set(tbl, 0, SS(fs));		/* 1st sector of the FAT  */
; 		if (fmt != FS_FAT32) {
; 			n = (fmt == FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00;
; 			n |= partition;
; 			ST_DWORD(tbl, n);				/* Reserve cluster #0-1 (FAT12/16) */
; 		} else {
; 			ST_DWORD(tbl+0, 0xFFFFFFF8);	/* Reserve cluster #0-1 (FAT32) */
; 			ST_DWORD(tbl+4, 0xFFFFFFFF);
; 			ST_DWORD(tbl+8, 0x0FFFFFFF);	/* Reserve cluster #2 for root dir */
; 		}
; 		if (disk_write(drv, tbl, b_fat++, 1) != RES_OK)
; 			return FR_DISK_ERR;
; 		mem_set(tbl, 0, SS(fs));		/* Following FAT entries are filled by zero */
; 		for (n = 1; n < n_fat; n++) {
; 			if (disk_write(drv, tbl, b_fat++, 1) != RES_OK)
; 				return FR_DISK_ERR;
; 		}
; 	}
; 
; 	/* Initialize Root directory */
; 	m = (BYTE)((fmt == FS_FAT32) ? allocsize : n_dir);
; 	do {
; 		if (disk_write(drv, tbl, b_fat++, 1) != RES_OK)
; 			return FR_DISK_ERR;
; 	} while (--m);
; 
; 	/* Create FSInfo record if needed */
; 	if (fmt == FS_FAT32) {
; 		ST_WORD(tbl+BS_55AA, 0xAA55);
; 		ST_DWORD(tbl+FSI_LeadSig, 0x41615252);
; 		ST_DWORD(tbl+FSI_StrucSig, 0x61417272);
; 		ST_DWORD(tbl+FSI_Free_Count, n_clst - 1);
; 		ST_DWORD(tbl+FSI_Nxt_Free, 0xFFFFFFFF);
; 		disk_write(drv, tbl, b_part+1, 1);
; 		disk_write(drv, tbl, b_part+7, 1);
; 	}
; 
; 	return (disk_ioctl(drv, CTRL_SYNC, (void*)NULL) == RES_OK) ? FR_OK : FR_DISK_ERR;
; }
; 
; #endif /* _USE_MKFS && !_FS_READONLY */
; 
; 
; 
; 
; #if _USE_STRFUNC
; /*-----------------------------------------------------------------------*/
; /* Get a string from the file                                            */
; /*-----------------------------------------------------------------------*/
; char* f_gets (
; 	char* buff,	/* Pointer to the string buffer to read */
; 	int len,	/* Size of string buffer */
; 	FIL* fil	/* Pointer to the file object */
; )
; {
; 	int i = 0;
; 	char *p = buff;
; 	UINT rc;
; 
; 
; 	while (i < len - 1) {			/* Read bytes until buffer gets filled */
; 		f_read(fil, p, 1, &rc);
; 		if (rc != 1) break;			/* Break when no data to read */
; #if _USE_STRFUNC >= 2
; 		if (*p == '\r') continue;	/* Strip '\r' */
; #endif
; 		i++;
; 		if (*p++ == '\n') break;	/* Break when reached end of line */
; 	}
; 	*p = 0;
; 	return i ? buff : NULL;			/* When no data read (eof or error), return with error. */
; }
; 
; 
; 
; #if !_FS_READONLY
; #include <stdarg.h>
; /*-----------------------------------------------------------------------*/
; /* Put a character to the file                                           */
; /*-----------------------------------------------------------------------*/
; int f_putc (
; 	int chr,	/* A character to be output */
; 	FIL* fil	/* Ponter to the file object */
; )
; {
; 	UINT bw;
; 	char c;
; 
; 
; #if _USE_STRFUNC >= 2
; 	if (chr == '\n') f_putc ('\r', fil);	/* LF -> CRLF conversion */
; #endif
; 	if (!fil) {	/* Special value may be used to switch the destination to any other device */
; 	/*	put_console(chr);	*/
; 		return chr;
; 	}
; 	c = (char)chr;
; 	f_write(fil, &c, 1, &bw);	/* Write a byte to the file */
; 	return bw ? chr : EOF;		/* Return the result */
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Put a string to the file                                              */
; /*-----------------------------------------------------------------------*/
; int f_puts (
; 	const char* str,	/* Pointer to the string to be output */
; 	FIL* fil			/* Pointer to the file object */
; )
; {
; 	int n;
; 
; 
; 	for (n = 0; *str; str++, n++) {
; 		if (f_putc(*str, fil) == EOF) return EOF;
; 	}
; 	return n;
; }
; 
; 
; 
; 
; /*-----------------------------------------------------------------------*/
; /* Put a formatted string to the file                                    */
; /*-----------------------------------------------------------------------*/
; int f_printf (
; 	FIL* fil,			/* Pointer to the file object */
; 	const char* str,	/* Pointer to the format string */
; 	...					/* Optional arguments... */
; )
; {
; 	va_list arp;
; 	UCHAR c, f, r;
; 	ULONG val;
; 	char s[16];
; 	int i, w, res, cc;
; 
; 
; 	va_start(arp, str);
; 
; 	for (cc = res = 0; cc != EOF; res += cc) {
; 		c = *str++;
; 		if (c == 0) break;			/* End of string */
; 		if (c != '%') {				/* Non escape cahracter */
; 			cc = f_putc(c, fil);
; 			if (cc != EOF) cc = 1;
; 			continue;
; 		}
; 		w = f = 0;
; 		c = *str++;
; 		if (c == '0') {				/* Flag: '0' padding */
; 			f = 1; c = *str++;
; 		}
; 		while (c >= '0' && c <= '9') {	/* Precision */
; 			w = w * 10 + (c - '0');
; 			c = *str++;
; 		}
; 		if (c == 'l') {				/* Prefix: Size is long int */
; 			f |= 2; c = *str++;
; 		}
; 		if (c == 's') {				/* Type is string */
; 			cc = f_puts(va_arg(arp, char*), fil);
; 			continue;
; 		}
; 		if (c == 'c') {				/* Type is character */
; 			cc = f_putc(va_arg(arp, int), fil);
; 			if (cc != EOF) cc = 1;
; 			continue;
; 		}
; 		r = 0;
; 		if (c == 'd') r = 10;		/* Type is signed decimal */
; 		if (c == 'u') r = 10;		/* Type is unsigned decimal */
; 		if (c == 'X') r = 16;		/* Type is unsigned hexdecimal */
; 		if (r == 0) break;			/* Unknown type */
; 		if (f & 2) {				/* Get the value */
; 			val = (ULONG)va_arg(arp, long);
; 		} else {
; 			val = (c == 'd') ? (ULONG)(long)va_arg(arp, int) : (ULONG)va_arg(arp, unsigned int);
; 		}
; 		/* Put numeral string */
; 		if (c == 'd') {
; 			if (val & 0x80000000) {
; 				val = 0 - val;
; 				f |= 4;
; 			}
; 		}
; 		i = sizeof(s) - 1; s[i] = 0;
; 		do {
; 			c = (UCHAR)(val % r + '0');
; 			if (c > '9') c += 7;
; 			s[--i] = c;
; 			val /= r;
; 		} while (i && val);
; 		if (i && (f & 4)) s[--i] = '-';
; 		w = sizeof(s) - 1 - w;
; 		while (i && i > w) s[--i] = (f & 1) ? '0' : ' ';
; 		cc = f_puts(&s[i], fil);
; 	}
; 
; 	va_end(arp);
; 	return (cc == EOF) ? cc : res;
; }
; 
; #endif /* !_FS_READONLY */
; #endif /* _USE_STRFUNC */
